我正在试图以有序方式获取json中的项目。我能够选择json中存在的“term”值,但是可以按照我在预期的输出部分中显示的方式来安排它吗?我添加了一个的jsfiddle链接显示在那里我已经达到:将JavaScript对象转换为有序的逗号分隔值
[{
"_index": "test",
"id": "YMFT112",
"_source": {
"Author": "SAM",
"Map": [
{
"count": 1,
"term": "Company",
"Company": [
{
"sector": "Technology",
"ticker": "AAPL",
"Apple_Inc": [
{
"count": 1,
"term": "Apple"
}
],
"term": "Apple Inc",
"type": "BCap"
}
]
},
{
"count": 1,
"term": "Country",
"Country": [
{
"region": "North Americas",
"index": "DOW JONES INDUS. AVG , S&P 500 INDEX , NASDAQ COMPOSITE INDEX",
"United_States": [
{
"count": 1,
"term": "United States"
}
],
"term": "United States",
"currency": "Dollar (USD)",
"Canada": [
{
"count": 1,
"term": "Canada",
"Canada" : [{
"count": 1,
"term":"Toronto"
}]
}
],
"term": "Canada",
"currency": "Dollar (USD)"
}
]
},
{
"count": 5,
"term": "Personality",
"Personality": [
{
"count": 1,
"term": "Bart Prince"
},
{
"count": 1,
"term": "Thomas"
},
{
"count": 1,
"term": "Deborah Hornstra"
},
{
"count": 1,
"term": "Henderson Sotheby"
},
{
"count": 1,
"term": "Max Alliance"
}
]
}
]
}
,
"Link": "http://testLink.com/1"
},
{
"_index": "test",
"_id": "YMFT113",
"_source": {
"Author": "MAX",
"Map": [
{
"count": 1,
"term": "Company",
"Company": [
{
"sector": "Technology",
"ticker": "AAPL",
"Microsoft Corp": [
{
"count": 1,
"term": "Microsoft"
}
],
"term": "Microsoft",
"type": "BCap"
}
]
},
{
"count": 1,
"term": "Country",
"Country": [
{
"region": "South Americas",
"Brazil": [
{
"count": 1,
"term": "Brazil"
}
],
"term": "Brazil",
"currency": "Dollar (USD)"
}
]
},
{"SalesRelated": [
{
"count": 1,
"term": "traffic"
}
]
},
{
"count": 4,
"term": "Personality",
"Personality": [
{
"count": 1,
"term": "Maximor"
},
{
"count": 1,
"term": "R.V.P"
},
{
"count": 1,
"term": "Wenger"
},
{
"count": 1,
"term": "SAF"
}
]
}
]
}
,
"Link": "http://testLink.com/2"
}]
http://jsbin.com/exuwet/3/edit
提示输入 如果字段中选择= Country
,
预期输出:
YMFT112; Country; United States; United States; NA; http://testLink.com/1;
YMFT112; Country; Canada; Canada; Toronto; http://testLink.com/1;
YMFT113; Country; Brazil; Brazil; NA; http://testLink.com/2;
如果选中字段= Company
,
预期输出:
YMFT112; Company; Apple Inc; Apple; http://testLink.com/1;
YMFT113; Company; Microsoft Corp; Microsoft; http://testLink.com/2;
你试过'eval('('+ json_object +')')'?从那里创建对象不会成为问题。 – cybertextron 2012-07-12 12:46:12
我没有尝试eval,实际上我看着它,我第一次处理josn字符串。 – user1371896 2012-07-12 12:48:26
我发布了我的答案。请按照说明操作,我相信您可以为您的问题创建解决方案。 – cybertextron 2012-07-12 12:55:54