【发布时间】:2016-08-03 08:52:11
【问题描述】:
我正在尝试解析 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"
你能帮我如何成功解析它吗?
【问题讨论】:
-
请发布您的代码 :)
-
@HuyN 我已经发布了!请看问题
-
你检查
resultParams[i]不为空吗? -
没错,因为它指出
Attempt to write to field未读,所以=的左侧是问题 -
更多代码请,这两行不能帮助我们找出问题。