开发者

How to take data from json object...?

开发者 https://www.devze.com 2023-03-26 21:25 出处:网络
I just start working with JSON data. [[[170, \"kod\", 148, 13, \"2011-07-11T03:33:57Z\", 11.68, 10.0, 1310373205707,\"2939393939\"]], [{\"announcement\": {\"post_by\": null, \"created_at\": \"2010-09

I just start working with JSON data.

[[[170, "kod", 148, 13, "2011-07-11T03:33:57Z", 11.68, 10.0, 1310373205707,     "2939393939"]], [{"announcement": {"post_by": null, "created_at": "2010-09-04T09:59:12Z", "announcement_category": null, "updated_at": "2010-09-04T09:59:12Z", "valid_till": "2010-09-04T09:59:00Z", "priority": null, "id": 3, "condtions": "", "message": "hello"}}]]

I want to get:

[170, "kod", 148, 13, "2011-07-11T03:33:57Z", 11.68, 10.0, 1310373205707, "0976741509"]

and

[{"announcement": {"post_by": null, "created_at": "2010-09-04T09:59:12Z", "announcement_category": null, "updated_at": "2010-09-04T0开发者_如何学编程9:59:12Z", "valid_till": "2010-09-04T09:59:00Z", "priority": null, "id": 3, "condtions": "", "message": "hello"}}]

in string

any idea?


Existing libraries for parsing JSON for Android/Java

There's an excellent answer to this posted here:

  • Sending and Parsing JSON Objects

I am surprised these have not been mentioned: but instead of using bare-bones rather manual process with json.org's little package, GSon and Jackson are much more convenient to use. So:

  • GSON
  • Jackson

So you can actually bind to your own POJOs, not some half-assed tree nodes or Lists and Maps. (and at least Jackson allows binding to such things too (perhaps GSON as well, not sure), JsonNode, Map, List, if you really want these instead of 'real' objects)

0

精彩评论

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