对象到字符串列表的JSON数组 [英] JSON Array on Objects to List of String

查看:112
本文介绍了对象到字符串列表的JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下JSON

[{
    "rowId": "03 EUR10580000"
}, {
    "rowId": "03 EUR10900001"
}, {
    "rowId": "03 EUR1053RUD*"
}, {
    "rowId": "033331"
}]

我想将它转换为字符串列表只有rowId的值,所以在这种情况下就像

and I would like to convert it to a List of String with only the values of the rowId, so in this case like

"03 EUR10580000"
"03 EUR10900001"
"03 EUR1053RUD*"
"033331"

我GSON fromJson做到了但作为回报,我得到了LinkedTreeMap的列表,并且在执行循环时失败。我想要一个简单的字符串列表。

I did it with Gson fromJson but in return I get a List of LinkedTreeMap and when I do a loop in fails. I would like instead a simple List of String.

推荐答案

那么,你的字符串不是字符串列表的json。它包含对象列表。所以你可以做的就是创建一个rowID作为字符串属性的类。

Well, your string is not a json of "list of string". It contains the list of objects. so what you can do is create a class with rowID as a string property.

class Data

class Data


  • rowID(type string)

然后,您可以使用Gson将此JSON字符串解析为List< Data> as used 此处

Then you can use Gson to parse this JSON string to List< Data > as used here

或者您必须手动准备新的json解析器。

or you have to prepare a new json parser manually.

这篇关于对象到字符串列表的JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆