【发布时间】:2014-11-03 14:14:04
【问题描述】:
我正在开发一个使用大量 json 的应用程序,我使用 Gson 进行解析,但它真的很慢,现在我正在尝试使用 Jackson,这是我第一次听说它,所以我不知道如何很好地使用它。 我的 json 是这样的:
{
"action": "login",
"status": true,
"message": "OK",
"duration": 144,
"response": {
"token": "b6a1e3b87c86531d91afa91bb23aca46"
}
}
我的反序列化课程就像:
public class HttpWebServiceObject {
private String action;
private boolean status;
private String message;
private String duration;
private String response;
//getters and setters
}
有人可以帮我解决这个问题吗?
提前致谢。
编辑:
我也可以有这样的json:
{
"action": "getUserFollowers",
"status": true,
"message": "OK",
"duration": 187,
"response": [
{
"id": "20810",
"name": "thyago",
"username": "thyago",
"location": "guarujá,brasil",
"photo": "profile/48d15179063126b40f6a5b1bbdea7f1e.jpg",
"following": false,
"numfollowing": 3,
"numfollowers": 7
},
{
"id": "933",
"name": "Edson Alves",
"username": "prazermatheus",
"location": "Rio de Janeiro, Brasil.",
"photo": "profile/bcc90c29054781adcd4569bb59251dba.jpg",
"following": false,
"numfollowing": 2689,
"numfollowers": 1373
},
{
"id": "753",
"name": "Yasmim Teófilo",
"username": "yasmim_gomesz",
"location": "Pacajus, Brasil",
"photo": "/profile/default.png",
"following": false,
"numfollowing": 1,
"numfollowers": 6
},
{
"id": "531",
"name": "Muriel Aragão",
"username": "muriaragao",
"location": "Salvador, Brasil",
"photo": "profile/0f6b504736723ea80c9cd15dabb3f0c5.jpg",
"following": false,
"numfollowing": 348,
"numfollowers": 32
},
{
"id": "492",
"name": "shashank",
"username": "shashank",
"location": "india",
"photo": "/profile/default.png",
"following": false,
"numfollowing": 5,
"numfollowers": 3
},
{
"id": "307",
"name": "Clineu Iansen",
"username": "clineu",
"location": "Curitiba, Brazil",
"photo": "profile/3d37a1e9c795a83c672ecacf575ee30a.jpg",
"following": false,
"numfollowing": 57,
"numfollowers": 946
},
{
"id": "277",
"name": "maharshi",
"username": "india",
"location": "india",
"photo": "profile/86d403617a30469f11403f0c9c65141b.jpg",
"following": true,
"numfollowing": 16,
"numfollowers": 1848
},
{
"id": "57",
"name": "Alexandre",
"username": "xandyhsf",
"location": "Itajai, Brasil",
"photo": "/profile/default.png",
"following": false,
"numfollowing": 51,
"numfollowers": 16
},
{
"id": "34",
"name": "Karina Ceconello Ton",
"username": "KarinaCeconello",
"location": "Quatro Barras/Brasil",
"photo": "profile/9bc1fb97263dc9a242766c87e4acf1c4.jpg",
"following": false,
"numfollowing": 5,
"numfollowers": 198
},
{
"id": "25",
"name": "Thiago Bodruk",
"username": "ThiagoBodruk",
"location": "Quatro Barras, Brazil",
"photo": "profile/56111881a4ebe0f0fc5cb85faa262e17.jpg",
"following": false,
"numfollowing": 26,
"numfollowers": 221
}
]
}
如何进行一般解析以反序列化并将响应作为字符串?
【问题讨论】:
-
鉴于 json 的大小,gson 应该不会很慢。
-
在这个请求中,gson 并不慢,但在其他方面是。
标签: android json parsing object jackson