我有一個大的JSON對象,當我要搜索的JSON對象特定的節點,我得到nullpointerexception
因爲空不存在,我的JSON是這樣搜索節點
"InternetGatewayDevice": {
"DeviceSummary": {
"_value": "InternetGatewayDevice:1.1[](Baseline:1, DeviceAssociation:1, Time:1, QoS:1, Bridging:1, IPPing:1, USBLAN:1, WiFiLAN:1, GponWAN:1), VoiceService:1.0[1](Endpoint:1, SIPEndpoint:1)",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
},
"DeviceInfo": {
"SpecVersion": {
"_value": "1.0",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
},
"HardwareVersion": {
"_value": "V1.0",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
},
"SoftwareVersion": {
"_value": "V1.1",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
},
"ProvisioningCode": {
"_value": "",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
}
},
"ManagementServer": {
"ConnectionRequestURL": {
"_value": "xxxxxx",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
},
"ParameterKey": {
"_value": "",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
}
},
"WANDevice": {
"1": {
"WANConnectionDevice": {
"10": {
"WANPPPConnection": {
"1": {
"ExternalIPAddress": {
"_value": "xxxxxx",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
},
"Username": {
"_value": "xxxxxxxx",
"_timestamp": "2014-12-01T09:07:09.943Z",
"_type": "xsd:string"
}
}
}
}
}
}
}
}
我尋找這個LANDevice
和我使用此代碼搜索節點::
JArray deviceJArray = JArray.Parse(jsonResult);
var strAuthModeBasic = deviceJArray[0]["InternetGatewayDevice"]["LANDevice"]["InternetGatewayDevice"]["LANDevice"]["1"]["WLANConfiguration"]["1"]["BeaconType"]["_value"].ToString();
,我想處理這個異常請。
你問在數據丟失時該怎麼辦,或者即使對於使用有效數據的json,你也總是得到這個異常? – 2014-12-04 09:23:38
當我錯過了數據。 – danarj 2014-12-04 09:24:32
是否知道'try ... catch'關鍵字? – 2014-12-04 09:25:13