这是一个doozie。试图找出如何重新格式化JSON响应并重新格式化数据
我有以下以.json格式的文件:
"response": {
"tickets": [
{
"alias": "Lower Box 122",
"curr_price": 16.0,
"quantity": 2,
"seats": "17,18",
},
{
"alias": "Lower Box 122",
"curr_price": 8.0,
"quantity": 5,
"seats": "1,2,3,4,5",
},
{
"alias": "Lower Box 122",
"curr_price": 14.0,
"quantity": 7,
"seats": "6,7,8,9,10,11,12",
},
{
"alias": "Lower Box 123",
"curr_price": 16.0,
"quantity": 2,
"seats": "17,18",
},
{
"alias": "Lower Box 123",
"curr_price": 8.0,
"quantity": 5,
"seats": "1,2,3,4,5",
},
{
"alias": "Lower Box 123",
"curr_price": 14.0,
"quantity": 7,
"seats": "6,7,8,9,10,11,12",
}
]
}
我试图让这个输出:
Lower Box 122,
quantity: 15,
seats: 1,2,3,4,5,6,7,8,9,10,11,12,17,18,
price: 8-16
Lower Box 123,
quantity: 15,
seats: 1,2,3,4,5,6,7,8,9,10,11,12,17,18,
price: 8-16
不幸的是,重新格式化原始JSON文件是不可能的。我必须处理它目前的格式。
我不一定再次需要.json格式。将文本分发到页面将会很好。任何人都可以指向我这样做的实用工具吗?或一个脚本,将这一切呢?
难度:仅限javascript。
我想感谢每个人都有一个答案 - 希望这会派上用场。
的Javascript与jQuery推测,因为你标记jQuery的。 – Orbling 2011-02-16 00:05:19
你如何获得这个文件到浏览器中,一个'.getJSON()`调用? – Orbling 2011-02-16 00:05:46
是。 getJSON - 我可以使用getScript也 – jake 2011-02-16 00:31:35