How can i deserialize this JSON - java

This is my JSON data i want to parse but am still new in deserialization, i want to get the following Attributes from this JSON data :
1.AirportCode.
2.Latutude.
3.Longitude.
This is the JSON containing two lists of the Airports.
{
"AirportResource": {
"Airports": {
"Airport": [{
"AirportCode": "AAL",
"Position": {
"Coordinate": {
"Latitude": 57.09305556,
"Longitude": 9.85
}
},
"CityCode": "AAL",
"CountryCode": "DK",
"LocationType": "Airport",
"Names": {
"Name": [{
"#LanguageCode": "xx",
"$": "Aalborg"
}, {
"#LanguageCode": "de",
"$": "Aalborg"
}, {
"#LanguageCode": "ru",
"$": "Ольборг"
}, {
"#LanguageCode": "pt",
"$": "Aalborg"
}, {
"#LanguageCode": "jp",
"$": "オールボア"
}, {
"#LanguageCode": "kr",
"$": "올보르그"
}, {
"#LanguageCode": "en",
"$": "Aalborg"
}, {
"#LanguageCode": "it",
"$": "Aalborg"
}, {
"#LanguageCode": "fr",
"$": "Aalborg"
}, {
"#LanguageCode": "es",
"$": "Aalborg"
}, {
"#LanguageCode": "ka",
"$": "奧爾堡"
}, {
"#LanguageCode": "pl",
"$": "Aalbork"
}, {
"#LanguageCode": "mi",
"$": "奥尔堡"
}]
},
"UtcOffset": 2,
"TimeZoneId": "Europe\/Copenhagen"
}, {
"AirportCode": "AAR",
"Position": {
"Coordinate": {
"Latitude": 56.30388889,
"Longitude": 10.62
}
},
"CityCode": "AAR",
"CountryCode": "DK",
"LocationType": "Airport",
"Names": {
"Name": [{
"#LanguageCode": "xx",
"$": "Aarhus"
}, {
"#LanguageCode": "en",
"$": "Aarhus"
}, {
"#LanguageCode": "de",
"$": "Aarhus"
}, {
"#LanguageCode": "it",
"$": "Aarhus"
}, {
"#LanguageCode": "fr",
"$": "Aarhus"
}, {
"#LanguageCode": "es",
"$": "Aarhus"
}]
},
"UtcOffset": 2,
"TimeZoneId": "Europe\/Copenhagen"
}]
},
"Meta": {
"#Version": "1.0.0",
"Link": [{
"#Href": "https:\/\/api.lufthansa.com\/v1\/references\/airports\/?limit=2&LHoperated=0&offset=0",
"#Rel": "self"
}, {
"#Href": "https:\/\/api.lufthansa.com\/v1\/references\/airports\/?limit=2&LHoperated=0&offset=2",
"#Rel": "next"
}, {
"#Href": "https:\/\/api.lufthansa.com\/v1\/references\/airports\/?limit=2&LHoperated=0&offset=1260",
"#Rel": "last"
}, {
"#Href": "https:\/\/api.lufthansa.com\/v1\/references\/cities\/{cityCode}",
"#Rel": "related"
}, {
"#Href": "https:\/\/api.lufthansa.com\/v1\/references\/countries\/{countryCode}",
"#Rel": "related"
}],
"TotalCount": 1261
}
}
}
Then my Java code:
EDITTED:
private void parseJson(String result)
{
try {
if (result!=null) {
JSONObject obj = new JSONObject(result).getJSONObject("AirportResource").getJSONObject("Airports");
JSONArray arr = obj.getJSONArray("Airport");
for (int i = 0; i < arr.length(); i++)
{
String AirportCode = arr.getJSONObject(i).getString("AAL");
String Latitude = arr.getJSONObject(i).getJSONObject("Position").getJSONObject("Coordinate").getString("Latitude");
String Longitude = arr.getJSONObject(i).getJSONObject("Position").getJSONObject("Coordinate").getString("Longitude");
System.out.println("Airport : " + AirportCode + " Latitude: " + Latitude+
" Longitude : " + Longitude );
}
}
else{
Toast.makeText(MainActivity.this,Config.POOR_NETWORK_CONNECTION, Toast.LENGTH_LONG).show();
}
}
catch (JSONException r){
System.out.println("ERROR PROB : "+ r);
}
}
The exception am getting is :
org.json.JSONException: No value for AirportResource
How can i parse this JSON kind of Data?

This will HOPEFULLY get you started.
private static void parseJson(JSONObject object) throws JSONException {
if (object!=null) {
JSONObject airportResource = object.getJSONObject("AirportResource");
JSONObject airports = airportResource.getJSONObject("Airports");
JSONArray airportArray = airports.getJSONArray("Airport");
for (int i = 0 ; i < airportArray.length(); i++) {
JSONObject airport = (JSONObject) airportArray.get(i);
//System.out.println(airport);
System.out.println("CityCode: " + airport.getString("CityCode"));
}
}
else{
//null
}
}
The output will be:
CityCode: AAL
CityCode: AAR

You didnt take the object of Airports. Inside Airports object is the Airport array and you are directly accessing it. Hence throwing error.
JSONObject obj2 = obj.getJSONObject("Airports");
Now get Json Array from obj
JsonArray jsonarray= obj2.getJsonArray("Airport");
Use the for loop on jsonarray's length now.

I recommend using this tool to view and formate your JSON properly.
this is the result
from here you could easily resolve your problem
JSONObject AirportResource= obj.getJSONObject("AirportResource");
JsonArray AirPorts= AirportResource.getJSONObject("Airports");
JsonArray jsonarray= AirPorts.getJsonArray("Airport");
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject obj= AirportResource.get(i); do sth with it
obj.getString("key"); //do sth with it
}

Related

how to parse the json response which starts with an array

response:
[
{
"id": "e9299032e8a34d168def176af7d62da3",
"createdAt": "Nov 8, 2017 9:46:40 AM",
"model": {
"id": "eeed0b6733a644cea07cf4c60f87ebb7",
"name": "color",
"app_id": "main",
"created_at": "May 11, 2016 11:35:45 PM",
"model_version": {}
},
"input": {
"id": "df6eae07cd86483f811c5a2202e782eb",
"data": {
"concepts": [],
"metadata": {},
"image": {
"url": "http://www.sachinmittal.com/wp-content/uploads/2017/04/47559184-image.jpg"
}
}
},
"data": [
{
"hex": "#f59b2d",
"webSafeHex": "#ffa500",
"webSafeColorName": "Orange",
"value": 0.0605
},
{
"hex": "#3f1303",
"webSafeHex": "#000000",
"webSafeColorName": "Black",
"value": 0.2085
},
{
"hex": "#a33303",
"webSafeHex": "#8b0000",
"webSafeColorName": "DarkRed",
"value": 0.3815
},
{
"hex": "#000000",
"webSafeHex": "#000000",
"webSafeColorName": "Black",
"value": 0.34275
},
{
"hex": "#f7ce93",
"webSafeHex": "#ffdead",
"webSafeColorName": "NavajoWhite",
"value": 0.00675
}
],
"status": {}
}
]
need to parse this reponse in json. Please help me out.
You can try something like this..
try{
JSONArray array= new JSONArray(Yourresponse);
for(int i=0; i<=array.length();i++){
JSONObject jsonObject=array.getJSONObject(i);
String id= jsonObject.getString("id");
String created_at= jsonObject.getString("createdAt");
String model_id = jsonObject.getJSONObject("model").getString("id");
String app_id=jsonObject.getJSONObject("model").getString("app_id");
//So On... Depends on your requirements. It's just an idea!
}
}
catch (Exception e){
e.printStackTrace();
}

How to create correct JsonArray in Java using JSONObject using servlet

how can I create a JSON Object like the following, in Java using JSONObject ?
[
{
"title": "ZAKI",
"start": "2010-05-01",
"placemarks": [
{
"polyline": [
{
"lat": 48.22467264956519,
"lon": 16.32568359375
},
{
"lat": 47.517200697839414,
"lon": 18.984375
},
{
"lat": 45.84410779560204,
"lon": 15.9521484375
},
{
"lat": 48.22467264956519,
"lon": 16.32568359375
}
]
},
{
"point": {
"lat": 48.22467264956519,
"lon": 16.32568359375
}
},
{
"point": {
"lat": 47.517200697839414,
"lon": 18.984375
}
},
{
"point": {
"lat": 45.84410779560204,
"lon": 15.9521484375
}
}
]
}
]
I'm using servlet.
This my servlet code
JSONArray arrayObj = new JSONArray();
for (int i = 0; i < listDataTracking.size(); i++) {
JSONObject obj = new JSONObject();
EntityTracking dataTracking = listDataTracking.get(i);
if (dataTracking.getIdTracking() == null) {
obj.put("Id", "");
} else {
obj.put("Id", dataTracking.getIdTracking());
obj.put("title", dataTracking.getUser_name().getUserName().toUpperCase());
obj.put("start", sdf.format(dataTracking.getTglSend()));
//
String lat = "";
String lon = "";
String jamSend = "";
Long id = 0l;
//
String queryStmnt_geoTracking = "SELECT entityGeoTracking.id FROM EntityGeoTracking entityGeoTracking "
+ "WHERE entityGeoTracking.idTracking.idTracking=\"" + dataTracking.getIdTracking() + "\"";
javax.persistence.Query query_geoTracking = em.createQuery(queryStmnt_geoTracking);
System.out.println("Isi queryStmnt_geoTracking" + queryStmnt_geoTracking);
List<EntityGeoTracking> cekid = query_geoTracking.getResultList();
if (cekid.isEmpty()) {
System.out.println("Isi cekid == null");
return;
}
System.out.println("Isi cekid" + cekid);
EntityGeoTracking dataGeoTraking = em.find(EntityGeoTracking.class, cekid);
if (lat.isEmpty()) {
lat = dataGeoTraking.getGetLatitude();
}
if (lon.isEmpty()) {
lon = dataGeoTraking.getGetLongitude();
}
if (id == 0l) {
id = dataGeoTraking.getId();
}
if (jamSend.isEmpty()) {
jamSend = dataGeoTraking.getJamSend();
}
System.out.println("chek value lat, lon, id, jamSend" + lat + "" + lon + "" + id + "" + jamSend);
javax.json.JsonArray value = Json.createArrayBuilder()
.add(Json.createObjectBuilder()
.add("polyline", Json.createObjectBuilder()
.add("lat", lat)
.add("lon", lon)))
.add(Json.createObjectBuilder()
.add("point", Json.createObjectBuilder()
.add("lat", lat)
.add("lon", lon)))
.build();
obj.put("placemarks", value);
}
arrayObj.add(obj);
}
em.close();
JSONObject rows = new JSONObject();
// rows.put("results", arrayObj);//results
// rows.put("results", listDataTracking.size());//results
// rows.put("rows", arrayObj);
// writer.print(rows.toString());
// rows.put("", listDataTracking.size());//results
rows.put("", arrayObj);
System.out.println(" List : " + arrayObj.toString());
writer.print(arrayObj);
writer.close();
// }
// br.close();
} catch (Exception ex) {
ex.getMessage();
System.out.println("ERROR: " + ex.getMessage());
} finally {
if (em != null && em.isOpen()) {
em.close();
}
}
}
My outPut JSON format
[
{
"Id": 1,
"title": "ZAKI",
"start": "2016-06-15",
"placemarks": [
{
"polyline": {
"lat": {
"chars": "-6.2206080",
"string": "-6.2206080",
"valueType": "STRING"
},
"lon": {
"chars": "106.7810640",
"string": "106.7810640",
"valueType": "STRING"
}
}
},
{
"point": {
"lat": {
"chars": "-6.2206080",
"string": "-6.2206080",
"valueType": "STRING"
},
"lon": {
"chars": "106.7810640",
"string": "106.7810640",
"valueType": "STRING"
}
}
}
]
}
]
I have tried it many times but I've been unsuccessful. Please help!
{
"title": "ZAKI",
"start": "2010-05-01",
"placemarks": [
{
"polyline": [
{
"lat": 48.2246726495652,
"lon": 16.32568359375
},
{
"lat": 47.5172006978394,
"lon": 18.984375
},
{
"lat": 45.844107795602,
"lon": 15.9521484375
},
{
"lat": 48.2246726495652,
"lon": 16.32568359375
}
]
},
{
"point": {
"lat": 48.2246726495652,
"lon": 16.32568359375
}
},
{
"point": {
"lat": 47.5172006978394,
"lon": 18.984375
}
},
{
"point": {
"lat": 45.844107795602,
"lon": 15.9521484375
}
}
]
}
First of All use some formatting tool to format your json so that you can easily understand the difference in expected vs actual output.
for the polyline object you should have an array rather than object with in a object.
Json.createObjectBuilder().add("polyline",
Json.createObjectBuilder().add("lat", lat).add("lon", lon))
)

How get array value from nested json data (java android)

I've got the title, author, and published date from json data to my android app.
I'm trying to get event_start_date and event_location, but failed. can anyone help me how I can get it?
Json:
{
"status": "ok",
"count": 1,
"count_total": 29,
"pages": 29,
"posts": [
{
"id": 2815,
"type": "event",
"slug": "itb-integrated-career-days",
"url": "http://example.com/event/itb-integrated-career-days/",
"status": "publish",
"title": "Title",
"title_plain": "Title",
"content": "<p>test</p>\n",
"excerpt": "<p>test […]</p>\n",
"date": "2015-09-25 01:09:40",
"modified": "2015-09-29 22:52:35",
"categories": [],
"tags": [],
"author": {
"id": 1,
"slug": "john",
"name": "john",
"first_name": "",
"last_name": "",
"nickname": "john",
"url": "",
"description": ""
},
"comments": [],
"attachments": [
{
"id": 2817,
"url": "http://example.com/wp-content/uploads/2015/09/bannertkt102015.gif",
"slug": "bannertkt102015",
"title": "bannertkt102015",
"description": "",
"caption": "",
"parent": 2815,
"mime_type": "image/gif",
"images": {
"full": {
"url": "http://example.com/wp-content/uploads/2015/09/bannertkt102015.gif",
"width": 1000,
"height": 563
},
"thumbnail": {
"url": "http://example.com/wp-content/uploads/2015/09/bannertkt102015-150x150.gif",
"width": 150,
"height": 150
},
"medium": {
"url": "http://example.com/wp-content/uploads/2015/09/bannertkt102015-300x169.gif",
"width": 300,
"height": 169
},
"large": {
"url": "http://example.com/wp-content/uploads/2015/09/bannertkt102015.gif",
"width": 1000,
"height": 563
},
"blog-default": {
"url": "http://example.com/wp-content/uploads/2015/09/bannertkt102015-806x300.gif",
"width": 806,
"height": 300
}
}
},
{
"id": 2818,
"url": "http://example.com/wp-content/uploads/2015/09/2015-09-25_012008.jpg",
"slug": "2015-09-25_012008",
"title": "2015-09-25_012008",
"description": "",
"caption": "",
"parent": 2815,
"mime_type": "image/jpeg",
"images": {
"full": {
"url": "http://example.com/wp-content/uploads/2015/09/2015-09-25_012008.jpg",
"width": 589,
"height": 529
},
"thumbnail": {
"url": "http://example.com/wp-content/uploads/2015/09/2015-09-25_012008-150x150.jpg",
"width": 150,
"height": 150
},
"medium": {
"url": "http://example.com/wp-content/uploads/2015/09/2015-09-25_012008-300x269.jpg",
"width": 300,
"height": 269
},
"large": {
"url": "http://example.com/wp-content/uploads/2015/09/2015-09-25_012008.jpg",
"width": 589,
"height": 529
},
"blog-default": {
"url": "http://example.com/wp-content/uploads/2015/09/2015-09-25_012008-589x300.jpg",
"width": 589,
"height": 300
}
}
}
],
"comment_count": 0,
"comment_status": "open",
"thumbnail": "http://example.com/wp-content/uploads/2015/09/2015-09-25_012008-150x150.jpg",
"custom_fields": {
"event_location": [
"New York"
],
"event_start_date": [
"10/23/2015"
],
"event_start_time": [
"09:00 AM"
],
"event_start_date_number": [
"1445590800"
],
"event_address_country": [
"US"
],
"event_address_state": [
"Jawdst"
],
"event_address_city": [
"New York"
],
"event_address_address": [
"Gedung Sasana Budaya Ganesha (Sabuga) Jalan Tamansari 73, New York"
],
"event_address_zip": [
"42132"
],
"event_phone": [
"5345"
],
"post_views_count": [
"23"
]
}
}
]
}
And my function
public void parseJson(JSONObject json) {
try {
info.pages = json.getInt("pages");
// parsing json object
if (json.getString("status").equalsIgnoreCase("ok")) {
JSONArray posts = json.getJSONArray("posts");
info.feedList = new ArrayList<PostItem>();
for (int i = 0; i < posts.length(); i++) {
Log.v("INFO",
"Step 3: item " + (i + 1) + " of " + posts.length());
try {
JSONObject post = (JSONObject) posts.getJSONObject(i);
PostItem item = new PostItem();
item.setTitle(Html.fromHtml(post.getString("title"))
.toString());
item.setDate(post.getString("date"));
item.setId(post.getInt("id"));
item.setUrl(post.getString("url"));
item.setContent(post.getString("content"));
if (post.has("author")) {
Object author = post.get("author");
if (author instanceof JSONArray
&& ((JSONArray) author).length() > 0) {
author = ((JSONArray) author).getJSONObject(0);
}
if (author instanceof JSONObject
&& ((JSONObject) author).has("name")) {
item.setAuthor(((JSONObject) author)
.getString("name"));
}
}
if (post.has("tags") && post.getJSONArray("tags").length() > 0) {
item.setTag(((JSONObject) post.getJSONArray("tags").get(0)).getString("slug"));
}
// TODO do we dear to remove catch clause?
try {
boolean thumbnailfound = false;
if (post.has("thumbnail")) {
String thumbnail = post.getString("thumbnail");
if (thumbnail != "") {
item.setThumbnailUrl(thumbnail);
thumbnailfound = true;
}
}
if (post.has("attachments")) {
JSONArray attachments = post
.getJSONArray("attachments");
// checking how many attachments post has and
// grabbing the first one
if (attachments.length() > 0) {
JSONObject attachment = attachments
.getJSONObject(0);
item.setAttachmentUrl(attachment
.getString("url"));
// if we do not have a thumbnail yet, get
// one now
if (attachment.has("images")
&& !thumbnailfound) {
JSONObject thumbnail;
if (attachment.getJSONObject("images")
.has("post-thumbnail")) {
thumbnail = attachment
.getJSONObject("images")
.getJSONObject(
"post-thumbnail");
item.setThumbnailUrl(thumbnail
.getString("url"));
} else if (attachment.getJSONObject(
"images").has("thumbnail")) {
thumbnail = attachment
.getJSONObject("images")
.getJSONObject("thumbnail");
item.setThumbnailUrl(thumbnail
.getString("url"));
}
}
}
}
} catch (Exception e) {
Log.v("INFO",
"Item "
+ i
+ " of "
+ posts.length()
+ " will have no thumbnail or image because of exception!");
e.printStackTrace();
}
if (item.getId() != info.ignoreId)
info.feedList.add(item);
} catch (Exception e) {
Log.v("INFO", "Item " + i + " of " + posts.length()
+ " has been skipped due to exception!");
e.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
This should do it
JSONObject custom_fields = post.getJSONObject("custom_fields");
JSONArray event_start_date_array = custom_fields.getJSONArray("event_start_date");
JSONArray event_location_array = custom_fields.getJSONArray("event_location");
String event_start_date = event_start_date_array.getString(0);
String event_location = event_location_array.getString(0);

How to read a JSON file in Java using org.json.simple package

I am going to get facebook read_books
The file is in this format:
{
"data": [
{
"id": "270170479804513",
"from": {
"name": "L I",
"id": "1000022"
},
"start_time": "2014-01-22T09:31:00+0000",
"publish_time": "2014-01-22T09:31:00+0000",
"application": {
"name": "Books",
"id": "174275722710475"
},
"data": {
"book": {
"id": "133556360140246",
"url": "https://www.facebook.com/pages/Pride-and-Prejudice/133556360140246",
"type": "books.book",
"title": "Pride and Prejudice"
}
},
"type": "books.reads",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
},
{
"id": "270170328",
"from": {
"name": "h",
"id": "100004346894022"
},
"start_time": "2014-01-22T09:29:42+0000",
"publish_time": "2014-01-22T09:29:42+0000",
"application": {
"name": "Books",
"id": "174275722710475"
},
"data": {
"book": {
"id": "104081659627680",
"url": "https://www.facebook.com/pages/Gulistan-of-Sadi/104081659627680",
"type": "books.book",
"title": "Gulistan of Sa'di"
}
},
"type": "books.reads",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
}
],
I need books titles and their URL. I run the below code but I get Exception in thread "main" java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to java.lang.String
while ((inputLine = in.readLine()) != null)
{
s = s + inputLine + "\r\n";
if (s == null) {
break;
}
t = t + inputLine + "\r\n";
}
in.close();
t = t.substring(0, t.length() - 2);
System.out.println(t);
Object dataObj =JSONValue.parse(t);
System.out.println(dataObj);
JSONObject dataJson = (JSONObject) dataObj;
JSONArray data = (JSONArray) dataJson.get("data");
for (Object o: data)
{
JSONObject indata= (JSONObject) o;
Object indatafirst=(JSONObjec`enter code here`t).get("0");
String inndata=(String) indatafirst.get("data");
System.out.println("inndata"+inndata);
}}
but it is not true
The problem is with the following line:
String inndata=(String) indatafirst.get("data");
The data field in the JSON is not a String, it's a nested JSON object.
"data": {
"book": {
"id": "104081659627680",
"url": "https://www.facebook.com/pages/Gulistan-of-Sadi/104081659627680",
"type": "books.book",
"title": "Gulistan of Sa'di"
}
}
This explains your ClassCastException.
Instead you should do something like:
JSONObject data = (JSONObject) indatafirst.get("data");
JSONObject book = (JSONObject) data.get("book");
String bookTitle = book.get("title");

JSONObject keys order reverse

I searched across many sources but could not find the answer to this one..
Its a know fact that a JSONObject keys are returned in reverse order.
Is there any way to recurse through a JSONObject in the correct order as appearing in JSON
String json;
JSONObject obj = new JSONObject(json)
Iterator<String> keys = json.keys() ---> order is reversed
I understand JSONObject is unordered, perhaps there is a way to order it????
JSON is of type below..and the keys start getting recursed from the bottom most styleHint tag
"sections": {
"1": {
"1": {
"1": {
"title": "xxx",
"text": "xxx",
"tags": {
"audience": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
},
"styleHint": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
}
}
},
"title": "xxx",
"text": "xxx",
"tags": {
"audience": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
},
"styleHint": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
}
}
},
"2": {
"title": "xxx",
"text": "xxx",
"tags": {
"audience": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
},
"styleHint": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
}
}
},
"title": "xxx",
"text": "xxx",
"tags": {
"audience": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
},
"2": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
},
"styleHint": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
}
}
},
"2": {
"title": "xxx",
"text": "xxx",
"tags": {
"audience": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
},
"styleHint": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
}
},
"anchor":"xxx"
},
"3": {
"1": {
"title": "xxx",
"text": "xxx",
"tags": {
"audience": {
"tag": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
},
"styleHint": {
"tag": {
"name": "xxx",
"title": "xxx",
"id": "xxx"
}
}
}
},
"title": "xxx",
"text": "xxx",
"tags": {
"audience": {
"1": {
"name": "xxx",
"title": "xxx",
"id": "xxxx"
}
},
"styleHint": {
"1": {
"name": "xx",
"title": "xxx",
"id": "xxxx"
}
}
}
}
}
How about that
Get your org.json.JSONObject source and change these
public ListIterator keys() {
ListIterator iter = new ArrayList(this.keySet()).listIterator();
return iter;
}
and
/**
* Construct an empty JSONObject.
*/
public JSONObject() {
this.map = new LinkedHashMap();
}
and
/**
* The map where the JSONObject's properties are kept.
*/
private final LinkedHashMap map;
and
public JSONObject(Map map) {
this.map = new LinkedHashMap();
if (map != null) {
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Map.Entry e = (Map.Entry) i.next();
Object value = e.getValue();
if (value != null) {
this.map.put(e.getKey(), wrap(value));
}
}
}
}
I hope I don't burn in hell for that.

Categories

Resources