PHP中的父,子JSON解析?(Parent, child JSON parsing in PHP?)
我有一个JSON文件,其结构如下:
{
"data": {
"last_all": {
"value": "1194999",
"value_int": "2342",
"display": "332",
"disp1": "953.3",
"current": "BLR"
},
"item": "NRF",
"low": "494.55"
}
}
我如何从last_all获取“display”的值?
这部分是我卡住的地方: print $obj['last_all']['display']; 你不能传递超过3个参数,所以我不能告诉PHP查看数据然后last_all然后显示。
I have a JSON file with a structure as below:
{
"data": {
"last_all": {
"value": "1194999",
"value_int": "2342",
"display": "332",
"disp1": "953.3",
"current": "BLR"
},
"item": "NRF",
"low": "494.55"
}
}
How would I go about getting the value from "display" from last_all?
This part is where I get stuck: print $obj['last_all']['display']; you cant pass more then 3 params so I cant tell PHP to look under data then last_all then display.
原文:https://stackoverflow.com/questions/16554675
更新时间:2020-02-25 15:37
最满意答案
简单的疏忽。 您在数组引用中缺少“数据”:
$obj = json_decode($json_string, true);
print $obj['data']['last_all']['display'];
Simple oversight. You're missing 'data' in your array reference:
$obj = json_decode($json_string, true);
print $obj['data']['last_all']['display'];
2013-05-15
相关问答
Python版本 这是在Python中: f = open("c:/dir/jsondec.json")
data = json.load(f)
node = data['properties']['stock']['properties']['warehouse']
print str(node)
PHP版本 这是它在PHP中的等价物: $f = file_get_contents('c:/dir/jsondec.json');
$data = json_decode($f, true);
$
...
$result['realm_rank']是一个字符串,而不是一个数组。 因此, foreach就会导致错误。 当数组未设置,或者为空或不是数组时,此错误会导致。 <?php
$json = file_get_contents("http://www.wowprogress.com/guild/eu/twisting-nether/hellenic%20horde/json_rank");
if ($json == false) {
throw new Exception("Failed To
...
好的,在您的JSON中,前面有一个UTF-8 BOM。 你能找到以下区别: {"project_name":"Jaguar","project_ORB_code":null,"project_manager":null,"project_abbr":"JR","project_mol_index":"2","project_comment":null}
和: {"project_name":"Jaguar","project_ORB_code":null,"project_manager":nu
...
有不同的方法来实现这一目标。 这些是我现在最简单的回忆: import groovy.json.JsonSlurper
String string = '''{
"-1": {
"startDate": "",
"modifiedBy": "",
"endDate": "",
"projectId": 1,
"build": "",
"projectKey": "TEST",
"started": ""
...
尝试这个,然后你应该能够在PHP脚本中调用$ _POST [“id”]。 这应该适用于其他请求,除了url和数据字段之外没有任何修改。 $http({
method: 'POST',
url: 'http://localhost:8080/sns/delete.php',
data: {id: user.id},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
...
以下是两种简洁的方法(一种是注释掉的),使用foreach()循环来实现所需的结果。 ( 演示 ): $data=json_decode($json,true);
$arr=$data['Monthly Time Series'];
foreach($arr as $k=>$v){
$result[]='['.strtotime($k).', '.implode(', ',$v).']'; // avoid naming each element
// or $result[]=
...
简单的疏忽。 您在数组引用中缺少“数据”: $obj = json_decode($json_string, true);
print $obj['data']['last_all']['display'];
Simple oversight. You're missing 'data' in your array reference: $obj = json_decode($json_string, true);
print $obj['data']['last_all']['display'
...
它的工作。 你只是忘了回显返回的值: function xcp_balance($wallet) {
$jarr = json_decode(file_get_contents('http://xcp.blockscan.com/api2.aspx?module=address&action=balance&btc_address='.$wallet),true);
$balance = $jarr['data'][1]['balance'];
if (is_numer
...
首先 ,您需要将$.toJSON(asetid)更改$.toJSON(asetid) JSON.stringify(asetid) 。 但是,如果您仍然想要使用$.toJSON(asetid) ,则需要在页面上包含来自http://code.google.com/p/jquery-json/的jquery-json插件。 其次 ,我认为ajax请求部分应该放在迭代器函数之外,否则,您将为表的每一行发出一个ajax请求。 这是修改后的代码: var Dataconvert;
var asetid
...
它应该是 :- $visits = json_decode($json, true);
foreach ($visits[0]["actionDetails"] as $data) {
echo $data["pageTitle"];
}
It should be :- $visits = json_decode($json, true);
foreach ($visits[0]["actionDetails"] as $data) {
echo $data["pag
...