JSON到XML的大量资源在线,但只有当它们采用正常的数组格式,而不是字典时。
有谁知道我应该怎么做?我想在我的项目中使用XML,但是当我转换它时,我得到以下几点没什么用处:
< 0 KiFRirIKU_I0FIXWj1j =" [object Object]" KiQPi-1EiURvD3zK2IY =" [object Object]"
我该怎么办?
JSON字典的示例如下:
[{
"-KiFRirIKU_I0FIXWj1j": {
"category": "1",
"id": "-KiFRirIKU_I0FIXWj1j",
"image_url": "",
"message": "Water leaking out side of it for ages now but it's coming out the bottom now too!",
"postcode": "LL53",
"reports": "0",
"status": "0",
"time": "21-04-2017 13:18:25",
"title": "Leaking Bath, L12 area!",
"user_id": "esO8EE8aoLM3bvKalHNvI9Hv7Ra2"
},
"-KiQPi-1EiURvD3zK2IY": {
"category": "3",
"id": "-KiQPi-1EiURvD3zK2IY",
"image_url": "/v0/b/fixee-164914.appspot.com/o/esO8EE8aoLM3bvKalHNvI9Hv7Ra2514653921592.jpg",
"message": "How much would it cost a week to keep this in decent shape? Had extortionate quotes and need it done cheap soon!",
"postcode": "LE11 3UQ",
"reports": "0",
"status": "0",
"time": "23-04-2017 16:25:23",
"title": "Gardener Required!!",
"user_id": "esO8EE8aoLM3bvKalHNvI9Hv7Ra2"
}]
答案 0 :(得分:0)
对于xml需要一个根节点,你的json中的根节点在哪里? 尝试使用如下转换器从xml工作到json:http://www.utilities-online.info/xmltojson/ 这样你就知道如何格式化xml以使json有效。
因此,对于您的示例,我首先创建了xml,然后将其转换为json:
<root>
<KiFRirIKU_I0FIXWj1j>
<category>1</category>
<id>-KiFRirIKU_I0FIXWj1j</id>
<image_url></image_url>
<message>Water leaking out side of it for ages now but it's coming out the bottom now too!</message>
<postcode>LL53</postcode>
<reports>0</reports>
<status>0</status>
<time>21-04-2017 13:18:25</time>
<title>Leaking Bath, L12 area!</title>
<user_id>esO8EE8aoLM3bvKalHNvI9Hv7Ra2</user_id>
</KiFRirIKU_I0FIXWj1j>
<KiQPi-1EiURvD3zK2IY>
<category>1</category>
<id>-KiFRirIKU_I0FIXWj1j</id>
<image_url></image_url>
<message>Water leaking out side of it for ages now but it's coming out the bottom now too!</message>
<postcode>LL53</postcode>
<reports>0</reports>
<status>0</status>
<time>21-04-2017 13:18:25</time>
<title>Leaking Bath, L12 area!</title>
<user_id>esO8EE8aoLM3bvKalHNvI9Hv7Ra2</user_id>
</KiQPi-1EiURvD3zK2IY>
</root>
导致:
{
"root": {
"KiFRirIKU_I0FIXWj1j": {
"category": "1",
"id": "-KiFRirIKU_I0FIXWj1j",
"message": "Water leaking out side of it for ages now but it's coming out the bottom now too!",
"postcode": "LL53",
"reports": "0",
"status": "0",
"time": "21-04-2017 13:18:25",
"title": "Leaking Bath, L12 area!",
"user_id": "esO8EE8aoLM3bvKalHNvI9Hv7Ra2"
},
"KiQPi-1EiURvD3zK2IY": {
"category": "1",
"id": "-KiFRirIKU_I0FIXWj1j",
"message": "Water leaking out side of it for ages now but it's coming out the bottom now too!",
"postcode": "LL53",
"reports": "0",
"status": "0",
"time": "21-04-2017 13:18:25",
"title": "Leaking Bath, L12 area!",
"user_id": "esO8EE8aoLM3bvKalHNvI9Hv7Ra2"
}
}
}