java解析json到安卓中活动中的对象
我有一个返回JSON的php脚本,如下所示:
[{"title":"Clothes are selling well","location":"Los Angeles","imageUrl":"xxx","pubDate":"2014-07-26 13:58:08","id":"1"},{"title":"Polo this summer","location":"UAE","imageUrl":"YYY","pubDate":"2014-07-26 18:05:26","id":"2"},{"title":"Samsung: New tablets","location":"Kuwait","imageUrl":"IIIIII","pubDate":"2014-07-26 18:05:26","id":"3"}]
我需要在我的活动类中解析这个json。有什么建议吗?我将创建具有以下属性的对象:
- 头衔
- 位置
- 图像URL
- 出版日期
提前谢谢
# 1 楼答案
根据这些属性创建类。 下载谷歌的Gson 类示例名称:
Objects
例如:希望能有帮助
# 2 楼答案
在Android中解析JSON非常容易。这就是如何解析当前的JSON-
如果您是解析JSON的新手,有很多简单的教程,比如-
# 3 楼答案
Jackson library帮助您自动将数据绑定到JSON或从JSON绑定数据
为了解析字符串,需要使用ObjectMapper对象
否则,您可以使用Android JSONTokener轻松地手动完成