-2

I have a json+collection string as following:

//code formated

 { "collection" :
 {
 "version" : "1.0",
"href" : "http://example.org/friends/",

"links" : [
  {"rel" : "feed", "href" : "http://example.org/friends/rss"}
],

"items" : [
  {
    "href" : "http://example.org/friends/jdoe",
    "data" : [
      {"name" : "full-name", "value" : "J. Doe", "prompt" : "Full Name"},
      {"name" : "email", "value" : "jdoe@example.org", "prompt" : "Email"}
    ],
    "links" : [
      {"rel" : "blog", "href" : "http://examples.org/blogs/jdoe", "prompt" : "Blog"},
      {"rel" : "avatar", "href" : "http://examples.org/images/jdoe", "prompt" : "Avatar", "render" : "image"}
    ]
  },

  {
    "href" : "http://example.org/friends/msmith",
    "data" : [
      {"name" : "full-name", "value" : "M. Smith", "prompt" : "Full Name"},
      {"name" : "email", "value" : "msmith@example.org", "prompt" : "Email"}
    ],
    "links" : [
      {"rel" : "blog", "href" : "http://examples.org/blogs/msmith", "prompt" : "Blog"},
      {"rel" : "avatar", "href" : "http://examples.org/images/msmith", "prompt" : "Avatar", "render" : "image"}
    ]
  },

  {
    "href" : "http://example.org/friends/rwilliams",
    "data" : [
      {"name" : "full-name", "value" : "R. Williams", "prompt" : "Full Name"},
      {"name" : "email", "value" : "rwilliams@example.org", "prompt" : "Email"}
    ],
    "links" : [
      {"rel" : "blog", "href" : "http://examples.org/blogs/rwilliams", "prompt" : "Blog"},
      {"rel" : "avatar", "href" : "http://examples.org/images/rwilliams", "prompt" : "Avatar", "render" : "image"}
    ]
  }      
],

"queries" : [
  {"rel" : "search", "href" : "http://example.org/friends/search", "prompt" : "Search",
    "data" : [
      {"name" : "search", "value" : ""}
    ]
  }
],

"template" : {
  "data" : [
    {"name" : "full-name", "value" : "", "prompt" : "Full Name"},
    {"name" : "email", "value" : "", "prompt" : "Email"},
    {"name" : "blog", "value" : "", "prompt" : "Blog"},
    {"name" : "avatar", "value" : "", "prompt" : "Avatar"}

  ]
}
} 
}

sample linK: http://amundsen.com/media-types/collection/examples/

Can you please help me on how to decode this message. I have to read items , queries into my code and also version etc. I have to do this on android. I am not able to get how to use JSONObject to fetch the items, queries into my code.

vaultah
  • 44,105
  • 12
  • 114
  • 143
kuldeep
  • 817
  • 10
  • 27
  • 1
    You can use gson library : https://code.google.com/p/google-gson/ – Piotr Golinski Apr 14 '15 at 12:09
  • Closed this question as there are many questions already exist over Stackoverflow. Try to search and implement by your own, if you would face any issue then post a new question. – Paresh Mayani Apr 14 '15 at 12:44

2 Answers2

0

For the array objects use JSONArray. Method arr.length() returns elements count, arr.get<type>(position) or just arr.get(position) for getting element.

Ircover
  • 2,406
  • 2
  • 22
  • 42
0

you may use: import org.json.JSONException; import org.json.JSONObject;

in the following way:

try {
    JSONObject myObj = new JSONObject("your json string");
} catch (JSONException e) {
                        e.printStackTrace();
                    }
blender
  • 361
  • 3
  • 16