Convert JSONArray to Object using GSON fromJson method
<p>I have a <code>WCF</code> <code>Webservice</code>, in which send a data model and i get this in <code>Android</code> by <code>JSon</code>(By Entity Framework),any ways,
I can successfully get that <code>JSON</code> by this code and store all <code>JSON</code> Objects in <code>JSONArray</code> in the <code>AsyncTas</code> class, and in :  </p>

<pre><code>public class Consume extends AsyncTask&lt;Void, Void, Void&gt; {

            InputStream inputStream = null;
            String result = "";
            private ArrayList&lt;Contact&gt; contacts = new ArrayList&lt;Contact&gt;();

        @Override
            protected Void doInBackground(Void... params) {
                String URL = "http://x.x.x.x/MyWCF/Service1.svc/rest/getContact";
                ArrayList&lt;NameValuePair&gt; param = new ArrayList&lt;NameValuePair&gt;();
                try {
                    HttpClient httpClient = new DefaultHttpClient();
                    HttpPost post = new HttpPost(URL);
                    post.setEntity(new UrlEncodedFormEntity(param));
                    HttpResponse httpResponse = httpClient.execute(post);
                    HttpEntity httpEntity = httpResponse.getEntity();
                    //post.setHeader("content-type", "application/json");
                    inputStream = httpEntity.getContent();

                } catch (UnsupportedEncodingException e1) {
                    Log.e("UnsupportedEncoding", e1.toString());
                    e1.printStackTrace();
                } catch (ClientProtocolException e2) {
                    Log.e("ClientProtocolException", e2.toString());
                    e2.printStackTrace();
                } catch (IllegalStateException e3) {
                    Log.e("IllegalStateException", e3.toString());
                    e3.printStackTrace();
                } catch (IOException e4) {
                    Log.e("IOException", e4.toString());
                    e4.printStackTrace();
                }
                try {
                    BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);

                    StringBuilder sBuilder = new StringBuilder();

                    String line = null;
                    while ((line = bReader.readLine()) != null) {
                        sBuilder.append(line + "\n");
                    }
                    inputStream.close();
                    result = sBuilder.toString();
                } catch (Exception e) {
                    Log.e("StringBuilding", "Error converting result " + e.toString());
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                try {
                    JSONObject object = new JSONObject(result);
                    JSONArray jArray = object.getJSONArray("getContactResult");  //here i create the JsonArray of all JsonObjects

//Here  is the solutions, We make a list of out Contact and make it as down

            List&lt;Contact&gt; contacts;
           Type listType = new TypeToken&lt;List&lt;Contact&gt;&gt;() {
           }.getType();
           contacts= new Gson().fromJson(String.valueOf(jArray), listType);

//And here solution is ended !

               } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
</code></pre>

<p>And i created a Contact <code>class</code> in <code>android</code>, by this code : </p>

<pre><code>    public class Contact {


 @SerializedName("name")
    private String name;

        @SerializedName("lastName")
        private String lastName;

        @SerializedName("phoneNumber")
        private String phoneNumber;

        @SerializedName("latitude")
        private String latitude;

        @SerializedName("longitude")
        private String longitude;

        public void setName(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public void setLastName(String lastName) {
            this.lastName = lastName;
        }

        public String getLastName() {
            return lastName;
        }

        public void setPhoneNumber(String phoneNumber) {
            this.phoneNumber = phoneNumber;
        }

        public String getPhoneNumber() {
            return phoneNumber;
        }

        public void setLatitude(String latitude) {
            this.latitude = latitude;
        }

        public String getLatitude() {
            return latitude;
        }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }

    public String getLongitude() {
        return longitude;
    }
}
</code></pre>

<p>And i parse this <code>JSONArray</code> by Old ways ! 
By this method : </p>

<pre><code>     ArrayList&lt;Contact&gt; setFields(JSONArray jsonArray) {
        ArrayList&lt;Contact&gt; contacts = new ArrayList&lt;Contact&gt;();
            for(int i=0; i&lt;jsonArray.length(); i++) {
                try {
                    Contact contact = new Contact();
                    JSONObject object = (JSONObject) jsonArray.get(i);
                    contact.setName(object.getString("name"));
                    contact.setLastName(object.getString("lastName"));
                    contact.setPhoneNumber(object.getString("phoneNumber"));
                    contact.setLatitude(object.getString("latitude"));
                    contact.setLongitude(object.getString("longitude"));
                    contacts.add(contact);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            return contacts;
        }
</code></pre>

<p>It works, but I do not want to handle and parse <code>JSONArray</code> by this old way and wanna use <code>GSON</code> instead,any one can help me with this sample?
Here is my <code>JSONArray</code> and <code>JSON</code> Object : </p>

<pre><code>    {
  "getContactResult": [
    {
      "id": 2041,
      "lastName": "xxxx",
      "latitude": xxx,
      "longitude": xxx,
      "name": "xxxx",
      "phoneNumber": "xxxx"
    }
  ]
}
</code></pre>

<p>Thx</p>