У меня есть большой объект JSON и когда я хочу, чтобы найти конкретный узел в объекте JSON я получаю nullpointerexception
потому, что нуль не существует, и моя JSON, как этопоиска в объекте 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 с действительными данными? –
, когда я пропускаю данные. – danarj
Знают ли слова 'try ... catch'? –