{"5303b93":["F2424F",40.53,22.97,0,0,0,"0000","T-LGTS2","A139","-",1421675730,"","","",1,0,"UPDATE-YOUR-FR24-APP",0],
"5323c35":["F2424F",50.10,14.26,51,0,0,"2104","T-LKPR27","A139","",1421675730,"","","",1,0,"UPDATE-YOUR-FR24-APP",0]}
Asked
Active
Viewed 1,465 times
0

Mohammad Faisal
- 5,783
- 15
- 70
- 117

safiuz
- 9
- 7
-
@frasnian what he is asking is how to parse JSON without the key in the key value pairs in the object – Rafael Jan 21 '15 at 05:59
-
Pardon me @frasnian as I am new to JSON. I am trying to parse JSON string like this- {"5303b93":["F2424F",40.53,22.97,0,0,0,"0000","T-LGTS2","K139","-",1421675730,"","","",1,0,"UPDATE-YOUR-APP",0], "5323c35":["F2424F",50.10,14.26,51,0,0,"2104","T-LKPR27","AK39","",1421675730,"","","",1,0,"UPDATE-YOUR-APP",0]} – safiuz Jan 21 '15 at 06:00
-
Thanks @Rafael for understanding the question. I tried below code from stackoverflow but dnt know how to proceed- JSONObject jsonObj = new JSONObject(response_str); JSONArray arrayJson = jsonObj.getJSONArray("DONT_KNOW_WAT_TO KEEP HERE"); for (int i = 0; i < arrayJson.length(); i++) { String values= arrayJson.getString(i); } – safiuz Jan 21 '15 at 06:09
-
Are you trying to iterate all the arrays but ignoring the keys? – ikettu Jan 21 '15 at 06:20
-
1@ikettu: yes I am doing that as i dnt have key. but my node is changing everytime as first its "5303b93" then "5323c35" and so on... – safiuz Jan 21 '15 at 06:23
2 Answers
0
Maybe something like this:
JSONObject jsonObj = new JSONObject(str);
JSONArray arrayJson = jsonObj.getJSONArray("5303b93");
for (int i = 0; i < arrayJson.length(); i++) {
String values= arrayJson.getString(i);
}
Since isnt "5303b93
" the key for first array?
If you want to iterate all the arrays ignoring the keys
JSONObject jsonObj = new JSONObject(str);
Iterator it = jsonObj.keys();
while (it.hasNext()) {
JSONArray arrayJson = jsonObj.getJSONArray((String)it.next());
for (int i = 0; i < arrayJson.length(); i++) {
String values= arrayJson.getString(i);
}
}

ikettu
- 1,203
- 12
- 17
0
try this
Strings.xml
<string name="json_data">{"5303b93":["F2424F",40.53,22.97,0,0,0,"0000","T-LGTS2","A139","-",1421675730,"","","",1,0,"UPDATE-YOUR-FR24-APP",0], "5323c35":["F2424F",50.10,14.26,51,0,0,"2104","T-LKPR27","A139","",1421675730,"","","",1,0,"UPDATE-YOUR-FR24-APP",0]}</string>
JAVA Code :
JSONObject jsonObj = null;
try {
jsonObj = new JSONObject(getString(R.string.json_data));
JSONArray jsonArray1 = jsonObj.getJSONArray("5303b93");
JSONArray jsonArray2 = jsonObj.getJSONArray("5323c35");
for(int i= 0 ; i<jsonArray1.length(); i++){
if(jsonArray1.getString(i) != null){
String tempStr = jsonArray1.getString(i);
if(tempStr != null)
Log.i("===First Array==="+i, "==="+tempStr+"===");
}
}
for(int i= 0 ; i<jsonArray2.length(); i++){
if(jsonArray2.getString(i) != null){
String tempStr = jsonArray2.getString(i);
if(tempStr != null)
Log.i("===Second Array==="+i, "==="+tempStr+"===");
}
}
} catch (JSONException e) {
e.printStackTrace();
}

sandeepmaaram
- 4,191
- 2
- 37
- 42
-
What is R in above code. Also I cnt use JSONArray jsonArray1 = jsonObj.getJSONArray("5303b93"); JSONArray jsonArray2 = jsonObj.getJSONArray("5323c35"); bcz 5303b93,5323c35 are not fixed.It will keep on changing everytime. – safiuz Jan 21 '15 at 07:11
-
the code JSONArray jsonArray1 = jsonObj.getJSONArray("5303b93"); is throwing compilation error "The method getJSONArray(String) is undefined for the type JSONObject" – safiuz Jan 21 '15 at 07:18
-
R indicates Resources in java. In the above code response getting from srtings.xml. If key values keep changing, get key and iterate array – sandeepmaaram Jan 21 '15 at 07:30
-
Ohh now i figure out u given code in reference to android but i am making use in my java standalone application – safiuz Jan 21 '15 at 07:41