I\'m trying to read JSON from string (obtained from web), but it returns null
.
Specifically, result.append(name + id);
gives me nulln
Use this method it's work for me,
private void extractJson(){
String jsonString="{\"rikeard\":{\"id\":2828822,\"name\":\"Rikeard\",\"profileIconId\":688,\"summonerLevel\":30,\"revisionDate\":1422917445000}}";
try {
JSONObject jsonObject=new JSONObject(jsonString);
if(jsonObject!=null){
jsonObject=jsonObject.optJSONObject("rikeard");
if(jsonObject!=null){
String id=jsonObject.optString("id");
Log.d("MainActivity","id="+id);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}