![](/img/trans.png)
[英]I need to iterate over a JSON array - not sure how to do it - have searched but still can't get a clue
[英]Not sure why I can't get the values of this array or decode the json
我正在调用应该返回JSON数组的API。 我收到这个:
Array
(
[0] => {"msg_id":"0t5OxT1ZP9VcF45L2","_text":"I want to reserve","entities":{"intent":[{"confidence":1,"value":"make_reservation","type":"value"}]}}
)
我知道它是JSON,因为a)文档说那是我应该得到的,b)我运行了isJson($response)
并得到true
。
我尝试使用json_decode
但是代码在执行时就死掉了(错误说它期望一个字符串并得到一个有意义的数组,但是如果我执行json_encode
,它将根据我的理解进一步编码json)。
据我了解,我只需要一种遍历此数组并获取entities: intent:
的"value:" key
。 但是我不知道如何得到它或我错了。
我试着做:
$val = $jsonArray[0]['entitites']['intent'][0]['value']
但是什么也没有出现。
您发布的数据是一个php数组,其中数组第一个元素的值是json字符串。
json_decode($response[0]);
您正在尝试解码具有编码值的PHP数组。
您应该改用json_decode($jsonArray[0])
,以便解码第一个数组键的值,因为这是实际的json字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.