我想解析Json對象;如何解析Android中的json對象?
{
"results":[
{
"face":{
"id":361122.0,
"photo_hash":"0a2aaff34fd576fc1caf711d88cbfd53",
"x1":699,
"x2":1020,
"y1":271,
"photo":" ",
"thumbnail":" ",
"meta":"",
"timestamp":"2016-07-28T08:50:43.710183",
"y2":592
},
"confidence":0.93187
},
{
"face":{
"id":361260.0,
"photo_hash":"767bf4df0c8a04361aaf5e6b74eb4d8c",
"x1":-25,
"x2":147,
"y1":10,
"photo":" ",
"thumbnail":" ",
"meta":"",
"timestamp":"2016-07-28T15:13:09.086390",
"y2":165
},
"confidence":0.926754
}
]
}
,我使用這樣的代碼解析confidence
和thumbnail
:
resultParams[i].confidence = jsonObject.getJSONArray("results").getJSONObject(i).getString("confidence");
resultParams[i].thumbnail = jsonObject.getJSONArray("results").getJSONObject(i).getJSONObject("face").getString("thumbnail");
但是它給了例外"java.lang.NullPointerException: Attempt to write to field on a null object reference"
能否請你幫我如何成功地解析呢?
請發佈您的代碼:) – alway5dotcom
@HuyN我已經發布!請參閱問題 – goGud
您是否檢查過'resultParams [i]'不爲null? – Fildor