android - Initialse a jsonArray java -
I'm trying to start a Jasonson Jason Array, but I'm losing in doing this.
I am wrong and how do we start a Jason array?
JSONArray template = {"header": "color", "item": [{" "Red", "first": true, "url": "#Red"}, {"name": "green", "link": true, "url": "#Green"}, {"name ":" Blue "," link ": true," url ":" #blue "}]," empty ": wrong};
You need to create a JSONObject of the template, which automatically items < Code> try {string template = "{\" header \ ": \" color \ "," + "\" item \ "": \ "name \": \ "red \", \ "before \": True, \ "url \": \ "# red \"}, "+" {\ "name \": \ "Green \", \ "link \": true, \ "url \": \ "# green \"}, "+" {\ "name \": \ "blue \", \ "link \": true Is, \ "url \": \ "#blue \"} "+"], \ "empty \": wrong} "; JSONObject jsonWithArrayInIt = New JSONObject (template); // JSONObject created for template JSONArray items = jsonWithArrayInIt.getJSONArray ("item"); // JSONArray of items obtained from JSONObject Println (items.toString ()); } Hold (JSONException je) {// error while creating JSON}
Comments
Post a Comment