通过url php获取Json信息

通过url php获取Json信息,php,json,url,undefined-index,Php,Json,Url,Undefined Index,我试图从Json url获取特定的数据,但我一直在研究如何获取所需的数据。“我的url”的输出如下所示: { "dev_settings_device":{"uuid":"eneco-001-018946:hdrv_zwave_63523C6205B", "name":"settings_device", "internalAddress":"settings_device", "type":"settings_device", "supportsCrc":"49", "location":"

我试图从Json url获取特定的数据,但我一直在研究如何获取所需的数据。“我的url”的输出如下所示:

{ 
"dev_settings_device":{"uuid":"eneco-001-018946:hdrv_zwave_63523C6205B", "name":"settings_device", "internalAddress":"settings_device", "type":"settings_device", "supportsCrc":"49", "location":"(null)"},
"dev_10":{"uuid":"eneco-001-018946:hdrv_zwave_69423C65F08", "name":"HAE_METER_v2", "internalAddress":"10", "type":"HAE_METER_v2", "supportsCrc":"1", "supportedCC":"22 3c 3d 3e 56 60 70 72 7a 86 8b 73", "IsConnected":"1", "HealthValue":"10", "location":"(null)"},
"dev_10.1":{"uuid":"eneco-001-018946:hdrv_zwave_69448735F0E", "name":"HAE_METER_v2_1", "internalAddress":"10.1", "type":"gas", "supportsCrc":"0", "CurrentGasFlow":"0.00", "CurrentGasQuantity":"670.00", "location":"(null)"},
"dev_10.2":{"uuid":"eneco-001-018946:hdrv_zwave_6945CFF5F0E", "name":"HAE_METER_v2_2", "internalAddress":"10.2", "type":"elec", "supportsCrc":"0", "CurrentElectricityFlow":"428.00", "CurrentElectricityQuantity":"49464.00", "location":"(null)"},
"dev_10.3":{"uuid":"eneco-001-018946:hdrv_zwave_69458EC5F0E", "name":"HAE_METER_v2_3", "internalAddress":"10.3", "type":"elec_delivered_nt", "supportsCrc":"0", "CurrentElectricityFlow":"NaN", "CurrentElectricityQuantity":"NaN", "location":"(null)"},
"dev_10.4":{"uuid":"eneco-001-018946:hdrv_zwave_6947CCD5F0E", "name":"HAE_METER_v2_4", "internalAddress":"10.4", "type":"elec_received_nt", "supportsCrc":"0", "CurrentElectricityFlow":"NaN", "CurrentElectricityQuantity":"NaN", "location":"(null)"},
"dev_10.5":{"uuid":"eneco-001-018946:hdrv_zwave_694D7AB5F0E", "name":"HAE_METER_v2_5", "internalAddress":"10.5", "type":"elec_delivered_lt", "supportsCrc":"0", "CurrentElectricityFlow":"NaN", "CurrentElectricityQuantity":"NaN", "location":"(null)"},
"dev_10.6":{"uuid":"eneco-001-018946:hdrv_zwave_6941EFB5F0E", "name":"HAE_METER_v2_6", "internalAddress":"10.6", "type":"elec_received_lt", "supportsCrc":"0", "CurrentElectricityFlow":"NaN", "CurrentElectricityQuantity":"NaN", "location":"(null)"}
}
我的文件看起来像这样

<?php
error_reporting(E_ALL);
/* Written by Ierlandfan */
/* 1-11-2015 */
/* Version 1.1 */

/* Change ip_toon to the IP of your Toon */ 
/* start of current Energy usage import */
$file_string_gas = file_get_contents('http://192.168.1.66/hdrv_zwave?
action=getDevices.json');
$parsed_json = json_decode($file_string_gas, true);
var_dump($parsed_json['dev_10.1']);

/* Create new virtual sensor and write down the idx value */
/* Define idxvalue here */
$gasUsage=$parsed_json['CurrentGasQuantity'];
$idx = 933;

/* If this script is not run locally on the Domoticz server change 127.0.0.1  
according to your Domoticz IP */
/* Send currentUsage to Domoticz */
$gasusage = curl_init("http://192.168.1.27:8080/json.htm?
type=command&param=udevice&idx=$idx&nvalue=0&svalue=$gasUsage");
curl_exec($gasusage);
echo $gasUsage; 
?>

我收到的错误是:PHP注意:未定义索引:第16行/home/pi/domoticz/scripts/PHP/gas_data_json1.PHP中的CurrentGasQuantity,但我不明白为什么。我尝试了几件事,但似乎我被卡住了。

CurrentGasQuantity
$parsed\uJSON['dev\u10.1']
的索引。因此,您可以按如下方式检索它:

$gasUsage= $parsed_json['dev_10.1']['CurrentGasQuantity']
小错误:

更正,
$gasUsage=$parsed_json['dev_10.1']['CurrentGasQuantity']

$gasUsage= $parsed_json['dev_10.1']['CurrentGasQuantity']