【发布时间】:2016-09-29 09:14:43
【问题描述】:
我有这种json文件:
{
"params": {
"apiKey": "key",
"sessionId": "123433890",
"lang": "en",
"timezone": "America/New_York",
"query": "hi all",
"latitude": "37.459157",
"longitude": "-122.17926",
"context": "[{"
name ": "
weather ","
lifespan ": 4}]"
}
}
因为
,它不是有效的 json"context": "[{"
name ": "
weather ","
lifespan ": 4}]"
我无法使用 json_decode 对其进行解码。
所以我想知道是否可以只解码第一个键。所以结果可能看起来像
array(1) {
'parameters' =>
array(8) {
'apiKey' =>
string(32) "key"
'sessionId' =>
string(10) "123433890"
'lang' =>
string(2) "en"
'timezone' =>
string(16) "America/New_York"
'query' =>
string(16) "hi all"
'latitude' =>
string(9) "37.459157"
'longitude' =>
string(10) "-122.17926"
'context' =>
string(16) "[{"name ": "weather ","lifespan ": 4}]"
}
}
谢谢!
这也是有效的 json,但不能用 json_decode 解码。
{
"query": [
"and for tomorrow"
],
"contexts": "[{'name':'weather', 'lifespan' : 4}]",
"location": {
"latitude": 37.459157,
"longitude": -122.17926
},
"timezone": "America/New_York",
"lang": "en",
"sessionId": "1234567890"
}
【问题讨论】:
-
你自己做json吗?
-
@KinshukLahiri 查看更新
-
“这也是有效的 json” - 不,不是。它缺少一个开口
{。 -
在PHP manual page on strings 中,它是“nowdoc”语法。