android wcf list,wcf rest - Android gson deserialization into list - Stack Overflow

I am trying to parse a json string into a list, or arraylist. I have the following json response coming from a WCF RESTful service I created for an Android project

[

{

"Class": "Lorem",

"Company": "Ipsum",

"Id": "XXXX",

"Name": "Avent"

},

{

"Class": "Consectetur",

"Company": "Adipiscing",

"Id": "YYYYY",

"Name": "Nulla"

}

]

I've read several examples of parsing gson results on here, but I'm having difficulty enacting a container class as I've seen. I've gotten it to read a single result into a Group class, but cannot get it to parse into any kind of List or ArrayList.

Group Class:

public class Group {

private String Id;

private String Name;

private String Class;

private String Company;

}

Group Container Class:

public class Groups {

private List GRP;

}

gson parsing statement:

Groups GRP = gson.fromJson(jsonString, Groups.class);

I did have to do some manipulation of the jsonString because it was showing up with some spaces in the string (after the commas), and it started working after I removed them, at least for parsing into a single element. Not sure if that effects anything, but figured I'd mention it.

Also, I tried do the

Type listType = new TypeToken>() {}.getType();

gson.toJson(myStrings, listType);

but that doesn't seem to work either, and I didn't know if that is necessary for my situation.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值