开发者

Parsing JSON through Gson method fromJson

I am parsing an API through

ArrayList<Spot> spots = Gson.fromJson(response , new TypeToken<Arraylist开发者_运维技巧<Spot>>(){}.getType())

My response is perfectly fine, but when I see the response through Gson.toJson(spots). It shows me empty objects, means it have parsed the first field of each object in the API but internals fields of each object is not parsed.

I receive null values if I access the internal fields which is obvious . Can any one let me know where the problem lies, why its not parsing any internal field? .


Maybe you have to use List instead of ArrayList. When you create your json use:

List<Spot> spots = new ArrayList<Spot>();
gson...

And when you parse the response use:

List<Spot> spots = Gson.fromJson(response , new TypeToken<List<Spot>>(){}.getType());

If that does not work, please show your json and the Spot class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜