ListView获取JsonArray php

The problem is that i dont know how to view "username" from friend array:

This is the json i'm recieving from php:

08-30 16:44:08.485    
1619-2810/com.gcator E/JSON﹕
{"tag":null,
 "success":1,
 "error":0,
 "friend":{
  "username":"Kerrigan",
  "latitude":"52.75315",
  "longitude":"15.22528"
 }
}
 {
 "tag":null,
 "success":1,
 "error":0,
 "friend":{
   "username":"Zahary",
   "latitude":"52.72423",
   "longitude":"15.24610"
 }
}

as You see array is broken too. This is the case if php recieve tag "getfriends" from android. I need to get friends in one array "friend" this is the code:

case 'getfriends':

        $id = $_POST ['id'];
        $response = array();

        $user = $db->getUserById($id);
        if($user){
            $friends = $db->getFriendsByUser($user);
            if($friends){
                for ($i = 0; $i < count($friends) ; $i++) {
                    $locationf = $db->getLocationByUser($friends[$i]);
                    $latitude = $locationf->getLatitude();
                    $longitude = $locationf->getLongitude();
                    $name = $friends[$i]->getUsername();

                    $response = new $response;
                    $response["friend"]['username'] = $name;
                    $response["friend"]['latitude'] = $latitude;
                    $response["friend"]['longitude'] = $longitude;


                }
                $response["success"]= 1;
                echo json_encode($response);
            } else {
                echo $response = "u dont have any Friends<br>";
            }
        } else {
            echo "dupa";
            echo var_dump($friends);
        }

, then use this friend array in android to List "username".

I did Async task where json is recieved but i dont know how to make loop that extract usernames of friends and put it do listviev, then on click will redirect to map activity

private class GetFriends extends AsyncTask<String, Void, JSONObject>
{
    private ProgressDialog pDialog;


    @Override
    protected void onPreExecute() {
        super.onPreExecute();


        pDialog = new ProgressDialog(FriendList.this);
        pDialog.setTitle("Contacting Servers");
        pDialog.setMessage("Searching Friends ...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }


    @Override
    protected JSONObject doInBackground(String... args) {

        SharedPreferences sharedPrefID = getSharedPreferences("userId", Context.MODE_PRIVATE);
        String ID = sharedPrefID.getString("KEY_ID", " dupa");


        UserFunctions userFunction = new UserFunctions();
        JSONObject json = userFunction.getFriends(ID);
        return json;
    }

    @Override
    protected void onPostExecute(JSONObject json) {

        try {
            if (json.getString(KEY_SUCCESS) != null) {

                String result = json.getString(KEY_SUCCESS);

                if(Integer.parseInt(result) == 1){
                    pDialog.setMessage("Loading View");
                    pDialog.setTitle("Getting Friends");

                }else{

                    pDialog.dismiss();
                    Labe.setText("There are no Friends :( Go to site make some !");
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }



        pDialog.dismiss();


    }
}

Any ideas/help ? Thanks :) I've searched but there was no good answer for me.

There is syntax error in your Json..response should be like..

[
  {
    "tag":null,
    "success":1,
    "error":0,
    "friend":{
        "username":"Kerrigan",
        "latitude":"52.75315",
        "longitude":"15.22528"
    }
  },
  {
    "tag":null,
    "success":1,
    "error":0,
    "friend":{
        "username":"Zahary",
        "latitude":"52.72423",
        "longitude":"15.24610"
    }
  }
]

Instead of passing json object pass whole json string to this method there you can put your condition easily... I have changed code below and added your condition...

Code onPost:

@Override
 protected void onPostExecute(String json){
   try {
    JSONObject root = new JSONObject(json);
    String result = root.getString("success");
    JSONArray user_array = root.getJSONArray("users");
        for (int i = 0; i < user_array.length(); i++) {
            JSONObject jsonObj = (JSONObject) user_array.getJSONObject(i);
              if(Integer.parseInt(result) == 1){
                pDialog.setMessage("Loading View");
                pDialog.setTitle("Getting Friends");
                String user = jsonObj.getString("username");
              }else{
                pDialog.dismiss();
                Labe.setText("There are no Friends :( Go to site make some !");
              }
        }
   }catch(JSONException e) {
     e.printStackTrace();
   }
 }

If Youre curious this is my solution ;) :

@Override
    protected void onPostExecute(JSONObject json) {
        try {
            if (json.getString(KEY_SUCCESS) != null) {
                String result = json.getString(KEY_SUCCESS);
                if (Integer.parseInt(result) == 1) {
                    pDialog.setMessage("Loading View");
                    pDialog.setTitle("Getting Friends");


                    //JSONArray root = new JSONArray(json);
                    JSONArray friend = json.getJSONArray("users");
                    List<String> item = new ArrayList<String>();

                    for (int i = 0; i < friend.length(); i++) {
                        JSONObject att = (JSONObject) friend.getJSONObject(i);

                        String res = att.getString("username");
                        item.add(res);



                    }



                    SharedPreferences FriendList = getSharedPreferences("FriendList", Context.MODE_PRIVATE);
                    SharedPreferences.Editor edit = FriendList.edit();
                    edit.putString("KEY_FRIENDS", item.toString());
                    edit.commit();
                } else {

                    pDialog.dismiss();

                }

            }else {

                pDialog.dismiss();

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        pDialog.dismiss();


    }

Its returning [Szamus,Zahariasz] now i need to get this and put it into ListView -.-