gpt4 book ai didi

java - Android中如何解析json对象?

转载 作者:行者123 更新时间:2023-12-02 03:26:47 24 4
gpt4 key购买 nike

我正在尝试解析 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
}
]
}

我正在使用这样的代码来解析confidencethumbnail:

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:尝试写入空对象引用上的字段”

您能帮我如何成功解析它吗?

最佳答案

给出这个答案:

"java.lang.NullPointerException: Attempt to write to field on a null object reference"

意味着你的左侧有问题。 resultParams[i] 很可能为 null。

关于java - Android中如何解析json对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38738828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com