I'm trying to pass a javascript array of items to a java server using JSON. my server receives the following String:
[
{"attr1":"SomeValue1","attr2":"SomeValue2"},
{"attr1":"SomeValue3","attr2":"SomeValue4"}
]
I'm trying to use JsonArray, but am probably doing it wrong (I'm not adding my code here since it is probably just stupid).
Can anyone give me the proper way of creating an iterating over the values from my String?
Edit: as requested, my stupid code:
jsnobject = new JSONObject(items); //items is the string described above
JSONArray jsonArray = jsnobject.getJSONArray("");
if(jsonArray != null){
for(int i=0 ; i<jsonArray.length();i++){
JSONObject explrObject = jsonArray.getJSONObject(i);
System.out.println("name = "+explrObject.get("fileName"));
}
}
JSONObjectandJSONArrayclasses must come from somewhere.