Response of JSON
[{
"ETag": "c28c2a1d",
"Id": "566668257",
"Links": [{
"Href": "\/v1\/companies\/566668257",
"Rel": "self"
}, {
"Href": "\/v1\/companies\/566668257",
"Rel": "parent"
}],
"Address": "412 S Van Buren",
"AddressParsed": {
"Name": "Van Buren",
"Number": "412",
"PreDirectional": "S"
},
"City": "Weiner",
"CompanyName": "Greenway Equipment Inc",
"FirstName": "John",
"LastName": "Conner",
"Location": {
"Latitude": 35.621407,
"Longitude": -90.910036
},
"Phone": "8706847720",
"PostalCode": "72479",
"StateProvince": "AR",
"ParentCompany": "566668257"
}]
My current code but I don't know how to get elements of Links
:
public void parseJSON(String parse) throws JSONException {
System.out.println("parse json");
JSONArray jsonarray = new JSONArray(parse);
int parselength = jsonarray.length();
JSONObject arraynode ;
String[] ID = new String[parselength];
String[] Etag = new String[parselength];
String[] City = new String[parselength];
String[] Address = new String[parselength];
**//String[][] Links = new String[parselength][parselength];**
System.out.println("parse"+parselength);
String strCSV = "";
strCSV = "ID, Etag, Links, Address\r\n";
for(int i=0; i<parselength-1; i++){
arraynode = jsonarray.getJSONObject(i);
ID[i] = arraynode.getString("Id");
City[i] = arraynode.getString("City");
Etag[i] = arraynode.getString("ETag");
Address[i] = arraynode.getString("Address");
//JSONArray innerLink = new JSONArray(arraynode.getString("Links"));
strCSV += Etag[i]+","+ID[i]+","+City[i]+","+Address[i]+"\r\n"; //
}
}
I can see the multidimensional array data in the inner loop when i check it from system.out.println but when i convert it into CSV it does not copy in CSV.
Can any on help me out in this.
Links is a field of my JSON Array as you can see in the response of JSON Array. It is a Multidimensional array.
When I execute my code it throws a error that Links not found.
My Ques is that how can I Convert this JSON Array into Java Array ? As i have done for the rest of the fields.
StringBuilder
forstrCSV
, 2/ you can declare all vars inside the loop (easier to get the size right forlinks
).