how to parse json result without array name in android

Related searches

I am trying to parse json result without array name. I tried differet methods but non of it works these are my code. So please someone tell me how to parse json result without using array name

thanks in advance.



I'm trying to parse this JSON


I expect it like this

private class CheckList extends AsyncTask<String, String, JSONObject> {

    private ProgressDialog mProgressDialog;

    protected void onPreExecute() {

        mProgressDialog = new ProgressDialog(Main2Activity.this);
        // Set progressdialog title
        mProgressDialog.setTitle("Please Wait");
        // Set progressdialog message
        // Show progressdialog;


        Main2Activity.this.runOnUiThread(new Runnable() {
            public void run() {



    protected JSONObject doInBackground(String... args) {
        final JParserAdv jParser = new JParserAdv();
        JSONObject json = jParser.makeHttpRequest("", "GET", null);
        return json;


    protected void onPostExecute(JSONObject json) {
        ArrayList<ITEM> data=new ArrayList<ITEM>();
        try {
            //need to insert array name here but json result I'm using is without array name.
            JSONArray arr = json.getJSONArray("arrayname");
            for(int i=0;i<arr.length();i++) {
                ITEM d = new ITEM();
                d.item_rank = ((JSONObject) arr.get(i)).get("id").toString();
                d.item_name = ((JSONObject) arr.get(i)).get("name").toString();
                d.item_population = ((JSONObject) arr.get(i)).get("address").toString();
            My_adapter adapter = new My_adapter(Main2Activity.this, data);
        }catch (Exception ex){ex.printStackTrace();}



First get the Employees into an array.

Then get the object at index=0. That should do the trick!


JSONArray employees = json.optJSONArray("employees");
JSONObject anEmployee = employees.optJSONObject(0);

How can i write Android Json parsing without array name, It's really simple you just have to get JSONArray object directly like this: ` @ Override protected Void doInBackground(Void arg0) { HttpHandler sh = new� There is also a simple solution. You can use google Gson library to parse json. All you have to do is create a class according to the json format i-e variable names same as name of json objects in json string/file.

It looks like the endpoint you are requesting returns a JSON structure that looks like the following:

    id: "710",
    name: "app",
    address: "k",
    gender: "h"

Since your root does not have an identifier, try returning an array as the root in your doInBackground() method.

private class CheckList extends AsyncTask<String, String, JSONArray> {


    protected JSONArray doInBackground(String... args) {
        final JParserAdv jParser = new JParserAdv();
        JSONArray json = jParser.makeHttpRequest("", "GET", null);
        return json;

    protected void onPostExecute(JSONArray json) {

I'm not sure what the JParseAdv API looks like, but hopefully there is a way to get it to return an array as the root of your JSON structure.

Parsing a Json array witout array name, json without field names json without object name json parsing in android how to get data from json array in android get json array from json object without key� For example, in the above example, the value for id is 912345678901, value for name is android_newb and so on. JSON Array Parsing Functions. Before parsing the JSON data, you have look for the JSON type i.e. you have to find if the JSON data is in the form of object or array. You can easily identify this by looking at your JSON file.

I had the same issue. The following code worked for me:

public class MainActivity extends AppCompatActivity {
    private TextView textView;
    private RequestQueue queue;

protected void onCreate(Bundle savedInstanceState) {

    textView = findViewById(;
    Button buttonParse = findViewById(;

    queue = Volley.newRequestQueue(this);

    buttonParse.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

private void jsonParse() {

    String url = ""; //This is my Json url
    StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        public void onResponse(String response) {
            //weatherData.setText("Response is :- ");
    }, new Response.ErrorListener() {
        public void onErrorResponse(VolleyError error) {
            textView.setText("Data Not Received");



private void parseData(String response) {
    try {
        // Create JSOn Object
        JSONArray jsonArray = new JSONArray(response);
        for (int i = 0; i <jsonArray.length() ; i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            textView.setText(jsonObject.getString("batteryLevel")); //get the desired information from the Json object

    } catch (JSONException e) {


Android - JSON Parser, This method returns an array containing the string names in this object. Example. To experiment with this example , you can run this on an actual device or in an� JSON Parsing In Android: Usually, JSON contain two types of nodes JSONArray and JSONObject so while parsing we have to use the appropriate method. If JSON starts from square bracket ([) we use getJSONArray() method and if it start from curly bracket ({) then we should use the getJSONObject() method. Apart from these there are some other methods for better parsing JSON data.

How to parse JsonArray or JsonObject with no field name. � Issue , How to parse JsonArray or JsonObject with no field name. So, my question is, how can I parse my List into LatLng object automatically ? Android provides support to parse the JSON object and array. Advantage of JSON over XML. 1) JSON is faster and easier than xml for AJAX applications. 2) Unlike XML, it is shorter and quicker to read and write. 3) It uses array. json object. A JSON object contains key/value pairs like map. The keys are strings and the values are the JSON types.

org.json.JSONObject.getJSONArray java code examples, getJSONArray (Showing top 20 results out of 6,993) getInt("name"); // throws JSONException - "name" entry isn't int int age = json. origin: ankidroid/Anki- Android entered by user, without any parsing */ public String getAnswerFormat () { try { JSONObject model = mCurrentCard.model(); JSONObject template; if ( model. Getting started with JSON in Android. In Android parse JSON object has two different of structures:. Collection of name/value pair; Array; The first structure can be used to model object because an object is a collection of attributes that hold some values.

I'm new to JSON, C languages, Java and also Android, but am learning. The tutorial uses what I'm calling a named array, but all of the JSON i'm going to be using in my android project will use simple table rows with no named array. Examples of the JSON i'm using and the earthquake json from the tutorial are below. The tutorial iterates through

  • Can you post a sample JSON that you're trying to parse. It'll be easier for us to answer then. Thanks.
  • [{"id":"710","name":"app","address":"k","gender":"h"}] I'm trying to parse this JSON {"employees":[{"id":"710","name":"app","address":"k","gender":"h"}]} I expect it like this
  • there is no method like json.getAsJsonArray in my code
  • Oops. I thought you were using the GSON library. I'll update my answer.
  • Is there any other way to parse without identifier
  • I updated my answer. Did you give that suggestion a try?
  • Don't know how to reutrn array as root in doInBackground () method.