how to get data from json array

  • Replies:1
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Oct 30, 2017, 3:05:49 PM via Website



  hot to get Accounts in a string value?

  • Forum posts: 1

Nov 5, 2017, 2:23:36 PM via Website

I think it's a JSONObject with a JSONArray inside (cmiiw). So, to get "Accounts" in a string value is:

String json = "{\"refersTo\":[\"Accounts\"]}";

String result = null; //use try-catch to use (cmiiw)
try {
JSONObject object = new JSONObject(json); //firts, get the jsonObject
JSONArray array = object.getJSONArray("refersTo"); //get the array with the key "refersTo"
result = array.getString(0); //"Accounts" is an element with index 0 in this array
} catch (JSONException e) {
System.out.println(result); //print "Accounts"

Recommended by NextPit