title: Convert Json without root element to object? using Gson, Ksoap2, Json.NET
body: <p>In my android application I'm getting this response from my web service:</p>
  
  <pre><code>[
  {
   "bookNum":1,
   "title":"Halo the fall",
   "author":"Erick Nylum"
  },
  {
   "bookNum":2,
   "title":"Halo contact",
   "author":"Erick Nylum"
  }
  ]
  </code></pre>
  
  <p>In android I'm trying to use this json to convert in an array or list object, because I don't have a root element  </p>
  
    <pre class="lang-java prettyprint-override"><code>        btnConsumer = (Button) this.findViewById(R.id.button1);
      btnConsumer.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              SoapObject request=new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);       
              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
              envelope.setOutputSoapObject(request);
              envelope.dotNet=true;       
              HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);// because AndroidHttpTransport now is d
              try {
                  httpTransport.debug = true; // ?
                  httpTransport.call(SOAP_ACTION, envelope);
                  Object response = (Object) envelope.getResponse();
                  lblView.setText(response.toString());
  
                  String jsonData= response.toString();
                  JSONObject json= new JSONObject(jsonData);
                  JSONObject data= json.getJSONObject("book");//no root ERROR
  
              }catch (JSONException e) {
                      // TODO: handle exception
                  e.printStackTrace();
              } catch (Exception e) {
                  // TODO: handle exception
                  lblView.setText(e.toString());
                  // lblView.setText(e.getMessage());
              }           
          }
      });
  </code></pre>
  
  <p>jsonData is my JSON string, I don't know how to transform to this object.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class books {
              @SerializedName("bookNum")
                  private String BookNum;
                  @SerializedName("title")
                  private String Title;
                  @SerializedName("author")
                  private String Author;
  
                  public books() {
                      // contructor vacio
                  }
  
                  public books(String bookNum, String title, String author) {
                      super();
                      this.setBookNum(bookNum);
                      this.setTitle(title);
                      this.setAuthor(author);
                  }
  
                  public String getBookNum() {
                      return BookNum;
                  }
  
                  public String getTitle() {
                      return Title;
                  }
  
                  public String getAuthor() {
                      return Author;
                  }
  
                  public void setBookNum(String bookNum) {
                      BookNum = bookNum;
                  }
  
                  public void setTitle(String title) {
                      Title = title;
                  }
  
                  public void setAuthor(String author) {
                      Author = author;
                  }
  
              }
  </code></pre>
  
  <p>My web services    </p>
  
    <pre class="lang-cs prettyprint-override"><code>[WebMethod(Description = "try return a LIST of book object in Json format using Newtonsoft")]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public string ShowAllBooks()
  {
      string url = "Server=localhost; database=books; password=system; user=sa;";
      MySqlConnection conn = new MySqlConnection(url);
      conn.Open();
  
      MySqlCommand command = conn.CreateCommand();
      //select
      command.CommandText = ("select * from reading");
      command.Connection = conn;
      MySqlDataReader reader = command.ExecuteReader();
  
      List&lt;Book&gt; listaBooks = new List&lt;Book&gt;();
  
      while (reader.Read())
      {
          Book book = new Book();
          book.bookNum = Convert.ToInt16(reader.GetString(0));
          book.title = reader.GetString(1).ToString();
          book.author = reader.GetString(2).ToString();
          listaBooks.Add(book);
      }
      command.Connection.Close();
  
      //var settings = new JsonSerializerSettings();
      //settings.TypeNameHandling = TypeNameHandling.Objects;
  
      //var typebook = Type.GetType("WS_Basico.Book");
      //string json = JsonConvert.SerializeObject(listaBooks,Formatting.Indented, settings); 
      string json = JsonConvert.SerializeObject(listaBooks, Formatting.Indented);
  
      return json;
  }  
  </code></pre>
  
  <p>But I can't, all methods that I saw (a lot) use a "root element" normally the object name, In my case I don't have one.
  What it's wrong?<br>
  I follow this <a href="https://www.youtube.com/watch?v=ZjzxJIT74UI" rel="nofollow">video</a> but he has a root element in his JSON (the object name).</p>
  
  <p>Somebody please give me tutorial or link or sample code?</p>
  
  <hr>
  
  <p>thanks a lot @Paresh.. you made my day.. With your help I still go ahead .. Actually I create a method that receive the jsonData and put the data in a listView following this <a href="http://vicentepalomero.blogspot.com/2013/04/android-anadir-y-eliminar-elementos-de.html" rel="nofollow">link</a> ... is the right way?</p>
  
    <pre class="lang-java prettyprint-override"><code>protected void ShowInView(String jsonData) {
      // TODO Auto-generated method stub
      JSONArray arrayResponse;
  
      try {
          arrayResponse = new JSONArray(jsonData);
          for (int i = 0; i &lt; arrayResponse.length(); i++) {
              JSONObject book = arrayResponse.getJSONObject(i);
              bookArrayList.add(Integer.toString(book.getInt("bookNum"))+" - "+book.getString("title"));
          }
          bookList.setAdapter(bookAdapter);
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Thank you!</p>