-3

我正在尝试(在 Javascript 和 Coldfusion 中)转换:

{"val1":"member","val2":"book","val3":"journal","val4":"new_member","val5":"cds"},

进入这个:

{ member,book,journal,new_member,cds}

请注意,我正在尝试消除引号。

有可能实现这一目标吗?我该怎么做?

4

2 回答 2

1

好的,所以这个: {"val1":"member","val2":"book","val3":"journal","val4":"new_member","val5":"cds"} 是 JSON。

要转换为 CF 结构,您可以这样:

myStruct = deserializeJSON('{"val1":"member","val2":"book","val3":"journal","val4":"new_member","val5":"cds"}');

(请注意,我的示例假设我们在一个<CFSCRIPT>块内操作。)现在您已经有了一个带有键/值对的简单结构。但是你想要一个值列表。所以让我们创建一个空字符串,然后将所有结构值附加到它:

myList = "";
for (k IN myStruct) {
  myList = listAppend(myList,myStruct[k]);
}

繁荣。myList 现在应该是 "member,book,journal,new_member,cds" 如果你真的想用花括号括起来。

myList = "{"&myList&"}";
于 2012-05-18T19:28:25.497 回答
0

首先,我要感谢您的回复。但是你们中的一些人必须对新手更有礼貌。

var tata = {"val1":"member","val2":"book","val3":"journal","val4":"new_member","val5":"cds"}
var arr=[]

for (var i in tata) {
    arr.push(tata[i])
}; 
console.log(arr);


wrd = new Array(arr)
var joinwrd = wrd.join(",");
console.log('{' + joinwrd + '}');
于 2012-05-19T04:51:01.290 回答