[
{
"id": 1,
"creationDate": null,
"updationDate": null,
"creationUserId": null,
"updationUserId": null,
"questions": "What is Android",
"answer": "Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google. ",
"deactivated": false
}
]
//this your json array i parse in following format
package com.example.jsondemo;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String jsonobj="[{\"id\":1,\"creationDate\":null,\"updationDate\":null,\"creationUserId\":null,\"updationUserId\":null,\"questions\":\"What is Android\",\"answer\":\"Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google.\",\"deactivated\":false}]";
// yuor json is correct. don't confuse about above json string jsut I created //json string for your understanding
try {
JSONArray ja=new JSONArray(jsonobj);
for (int count = 0; count < ja.length(); count++)
{
JSONObject obj = ja.getJSONObject(count);
int ID = obj.getInt("id");
String CreationDate=obj.getString("creationDate");
String UpdationDate=obj.getString("updationDate");
String CreationUserId=obj.getString("creationUserId");
String Questions=obj.getString("questions");
String Answer = obj.getString("answer");
boolean Deactivated=obj.getBoolean("deactivated");
Log.d("test", "user id"+" "+ID);
Log.d("test", CreationDate);
Log.d("test", UpdationDate);
Log.d("test", CreationUserId);
Log.d("test", Questions);
Log.d("test", Answer);
Log.d("test","check"+ " "+Deactivated);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//please check logcat test value it sucessfull work
0
solved I am not able to get why showing exception while I parcing JSON like “JSONObject cannot be converted to JSONArray” in my android project