本文介绍了coldfusion json解析问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下json字符串,需要提取每个survey_id
值作为列表.即74448500,74052991,65442357
I have the following json string and need to extract each of the survey_id
values as a list. ie 74448500, 74052991, 65442357
{
"status":0,
"data":{
"surveys":[
{
"survey_id":"74448500"
},
{
"survey_id":"74052991"
},
{
"survey_id":"65442357"
}
],
"page":1,
"page_size":1000,
"metadata":{
"collaboration":{
"shared_by_total":0,
"unfiled_owned_total":143,
"shared_with_total":0,
"owned_total":242
}
}
}
}
推荐答案
不确定您使用的是ColdFusion的哪个版本,可以通过以下两种方法来实现:
Not sure what version of ColdFusion you are on, here are two possible ways to do it:
<cfscript>
x = deserializeJSON('{"status":0,"data":{"surveys":[{"survey_id":"74448500"},{"survey_id":"74052991"},{"survey_id":"65442357"}],"page":1,"page_size":1000,"metadata":{"collaboration":{"shared_by_total":0,"unfiled_owned_total":143,"shared_with_total":0,"owned_total":242}}}}');
// ColdFusion 11
y = x.data.surveys.map(function(item){
return item.survey_id;
});
writeDump(arrayToList(y));
// ColdFusion 9+
z = [];
for (item in x.data.surveys) {
arrayAppend(z, item.survey_id);
}
writeDump(arrayToList(z));
</cfscript>
这篇关于coldfusion json解析问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!