- Forum posts: 1
Oct 30, 2017, 3:05:49 PM via Website
Oct 30, 2017 3:05:49 PM via Website
json----
{"refersTo":["Accounts"]}
hot to get Accounts in a string value?
Oct 30, 2017, 3:05:49 PM via Website
Oct 30, 2017 3:05:49 PM via Website
json----
{"refersTo":["Accounts"]}
hot to get Accounts in a string value?
Nov 5, 2017, 2:23:36 PM via Website
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:
//assume
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) {
e.printStackTrace();
}
System.out.println(result); //print "Accounts"