我正在尝试解析下面JSON中的符号:
$trending_url = "https://api.stocktwits.com/api/2/trending/symbols/equities.json";
此处的回复示例:
{
"response": {
"status": 200
},
"symbols": [{
"id": 11631,
"symbol": "JNUG",
"title": "Direxion Daily Jr Gld Mnrs Bull 3X Shrs",
"is_following": false
}, {
"id": 9553,
"symbol": "NUGT",
"title": "Direxion Daily Gold Miners Bull 3X Shrs",
"is_following": false
}, {
"id": 12100,
"symbol": "BABA",
"title": "Alibaba",
"is_following": false
}]
}
从JSON上面 - 我想通过循环提取符号(即JNUG,NUGT,BABA)。这就是我做的......
$trending_url_info = json_decode(file_get_contents($trending_url),true);
echo $trending_url_info->symbols->symbol[0] . "<br>";
echo $trending_url_info->response->symbols->symbol[0] . "<br>";
echo $trending_url_info->response->symbols[0]->symbol[0] . "<br>";
echo $trending_url_info['response']['symbols'][0]['symbol'] . "<br>";
echo $trending_url_info['response']['symbols'][0]['symbol'][0] . "<br>";
echo $trending_url_info['response']['symbols']['symbol'][0] . "<br>";
然而上面没有一个回声给我这个符号。我如何循环并从JSON提要中提取符号?任何帮助都是适用的。谢谢。
答案 0 :(得分:2)
update
不在draw
下。这就是update
这些都不起作用的原因。 Group
symbols
response
也会使关联数组不是对象。
$trending_url_info['response']...
这应该有效。
json_decode
true
会给$trending_url_info['symbols'][0]['symbol']
答案 1 :(得分:1)
这是对这些属性的正确访问的简单演示:
<?php
$jsonInput = <<<EOT
{
"response": {
"status": 200
},
"symbols": [{
"id": 11631,
"symbol": "JNUG",
"title": "Direxion Daily Jr Gld Mnrs Bull 3X Shrs",
"is_following": false
}, {
"id": 9553,
"symbol": "NUGT",
"title": "Direxion Daily Gold Miners Bull 3X Shrs",
"is_following": false
}, {
"id": 12100,
"symbol": "BABA",
"title": "Alibaba",
"is_following": false
}]
}
EOT;
$jsonData = json_decode($jsonInput);
foreach ($jsonData->symbols as $symbol) {
var_dump($symbol->symbol);
}
输出显然是:
string(4) "JNUG"
string(4) "NUGT"
string(4) "BABA"
答案 2 :(得分:0)
myselect.attr('contenteditable', 'true');
myselect.find('br').remove();
&#13;