I am trying to parse a json array from json string but it always throws the exception data of type java.lang.String cannot be converted to JSONArray
.
Please tell me if I make any mistake.
Thanks.
Here is my codes to get Json from server:
try {
String url = String.format(<url here>, province.provinceCode2);
HttpClient httpClient = getHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
final String result = EntityUtils.toString(entity);
parseAndSaveJsonData(province, result);
} catch (Exception e) {
e.printStackTrace();
}
here is codes to parse JsonArray:
String jsonString = <below json string>
JSONArray ja = new JSONArray(jsonString);
Here is my json string:
[
{
"LotPrizes":[
{
"Prize":"Gi?itám",
"Range":"50"
},
{
"Prize":"Gi?ib?y",
"Range":"264"
},
{
"Prize":"Gi?isáu",
"Range":"3654-5162-3097"
},
{
"Prize":"Gi?in?m",
"Range":"9739"
},
{
"Prize":"Gi?it?",
"Range":"97690-99274-32442-69432-04855-10132-17085"
},
{
"Prize":"Gi?iba",
"Range":"73745-13007"
},
{
"Prize":"Gi?inhì",
"Range":"05521"
},
{
"Prize":"Gi?inh?t",
"Range":"74870"
},
{
"Prize":"Gi?iDB6",
"Range":"878833"
}
]
},
{
"LotPrizes":[
{
"Prize":"Gi?itám",
"Range":"50"
},
{
"Prize":"Gi?ib?y",
"Range":"264"
},
{
"Prize":"Gi?isáu",
"Range":"3654-5162-3097"
},
{
"Prize":"Gi?in?m",
"Range":"9739"
},
{
"Prize":"Gi?it?",
"Range":"97690-99274-32442-69432-04855-10132-17085"
},
{
"Prize":"Gi?iba",
"Range":"73745-13007"
},
{
"Prize":"Gi?inhì",
"Range":"05521"
},
{
"Prize":"Gi?inh?t",
"Range":"74870"
},
{
"Prize":"Gi?iDB6",
"Range":"878833"
}
]
}
]
See Question&Answers more detail:
os