I get this message:
The type of the expression must be an array type but it resolved to
JSONArray
It happens on this line in the below java code:
JSONObject unit = units[i];
units[i] should be holding { id:3001, markers: [...]}.
I have json data that looks like this:
result = {
status:200,
error:null,
data:
{
units:
[
{
id:3001,
markers:
[
{latitude:28.92977431,longitude:-82.0193,address:unknown},
{latitude:22.92977431,longitude:-42.0193,address:unknown},
{latitude:33.92977431,longitude:-66.0193,address:unknown}
]
}
]
}
}
Here's my java code:
MapString,String reportData1 = new HashMapString, String();
ListMapString , String reportData = new
ArrayListMapString,String();
String result = QWebservice.getWebResource(
WEBSERVICE,
query);
try {
JSONObject jsonResult = new JSONObject(result);
JSONObject data = jsonResult.getJSONObject(data);
JSONArray units = data.getJSONArray(units);
for(int i = 0 ; i units.length(); i++){
JSONObject unit = units[i];
JSONObject reports =
unit.getJSONArray(markers);
for(int j = 0; j reports.length(); j++){
report = reports[j];
Iterator iter = report.keys();
while(iter.hasNext()){
String key =
(String)iter.next();
if(key.equals(latitude)){
reportData1.put(latitude, report.getString(key));
reportData.add(j,reportData1);
}
if(key.equals(longitude)){
reportData1.put(longitude, report.getString(key));
reportData.add(j,reportData1);
}
if(key.equals(address)){
reportData1.put(address, report.getString(key));
reportData.add(j,reportData1);
}
}
}
}
} catch (JSONException e) {
Log.e(log_tag, Error parsing data + e.toString());
}
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en