【发布时间】:2017-09-28 17:22:45
【问题描述】:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetCategoriesJsonResponse xmlns="http://tempuri.org/">
<GetCategoriesJsonResult>[{"code":"0","description":"Sides","storeNumber":"3733"},{"code":"1","description":"Sandwiches","storeNumber":"3733"},</GetCategoriesJsonResult>
</GetCategoriesJsonResponse>
</s:Body>
</s:Envelope>
这是 API 的结果,但我想将其转换为:
[
{
"code": "0",
"description": "Sides",
"storeNumber": "3733"
},
{
"code": "1",
"description": "Sandwiches",
"storeNumber": "3733"
},
]
我该怎么做?我试过json_encode 和json_decode 但对我不起作用。我已经应用了不同的方法来转换它,但它仍然显示 XML 结果。谁能告诉我如何将其转换为 JSON?
【问题讨论】:
-
您是否尝试将其从文本转换为对象?或者您是否想在单独的行上漂亮地打印 JSON?
-
我想获得 json 响应以在其中进行迭代我如何在 php 中做到这一点