【发布时间】:2014-12-09 18:27:23
【问题描述】:
我正在尝试解析 JSON 值并解析我需要的内容。
基本上,我只想捕获标记为“Most_Likely”的值。
另外,如果有 OR 语句,我需要将这些值分开。
这是我的尝试,但我遇到了 JS 错误:
for (i = 0; i < obj1.Summary.length; i++) {
for (j in obj1.Summary[i]) {
if (j.indexOf('Most_Likely') && obj1.Summary[i][j].indexOf('|OR|') >= 0){
var tempvalue = obj1.Summary[i][j].indexOf('Most_Likely').split(" |OR| ");
attributesvalues.push(tempvalue);
alert(attributesvalues);
}
else{
//do nothing
}
}
}
//JSON 示例
var obj1 = {
"Summary" :
[
{
"host:Most_Likely" : "www.google.com",
"host:Indicative" : "www.yahoo.com |OR| www.google.com",
"term:Most_Likely" : "cars" |OR| new cars |OR| SUVs,
"term:Indicative" : "automatic |OR| Lexus |OR| SUVs |OR| Civic"
}
]
};
【问题讨论】:
-
一个alternative implementation,以防您对更“功能性编程”的方式感到好奇。
标签: javascript json parsing