-1

The JSON is :

    {
  "statuses": [
    {
      "created_at": "Fri Dec 02 17:05:40 +0800 2016",
      "id": 4048283825629844,
      "mid": "4048283825629844",
      "user": {
        "id": 5680719858,
        "idstr": "5680719858",
        "class": 1
        },
      "is_show_bulletin": 2
    },
    .......

I don't know the "user" key is what kind of Java object type.

Please give me a sample code to show how to parse this json. Many thanks!

Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105

2 Answers2

1

I don't know the "user" key is what kind of java object type.

It isn't a Java standard library class. It's a user defined POJO. The Gson documentation discusses these.

For example, this post shows a similar User class.

Mapping JSON into POJO using Gson

It is up to you to create the wrapper objects, with the correct fields as necessary, or use generators such as http://www.jsonschema2pojo.org

Community
  • 1
  • 1
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
-1

Download Google Gson.jar from here

http://www.java2s.com/Code/Jar/g/Downloadgson222jar.html

Then add the following code to your java file

import com.google.gson.Gson; // import this package

and then you can try this

Gson gson = new GsonBuilder().setPrettyPrinting().create();
string jsondata = gson.toJson("your object"); // pass your object here it will convert to json

for reverse you can do this

gson.fromJson("your json string", "your class");

JRA
  • 467
  • 5
  • 18