无法在javascript中解析多个json行

I am using twitterapi to get the friends list in php and I have encoded the result as a json array, but I cannot parse the json array in javascript.I have validated the json array produced by the php and its a valid json array. Below is my code.

php

$friends = array();
$friend_list = array();
$myfriend = array();
$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_SECRET,oauth_token,oauth_token_secret);
 $friends =$connection->get("https://api.twitter.com/1.1/friends/list.json?cursor=-1&screen_name=twitterapi&skip_status=true&include_user_entities=false&count=200);

foreach($friends as $friend) {
           if(!empty($friend))
           {
           foreach($friend as $value)
           {
                $friend_list['id']=$value->id; 
                $friend_list['screen_name']= $value->screen_name;
                $friend_list['name']= $value->name;
                $friend_list['profile_image_url']= $value->profile_image_url;
                $friend_list['location']= $value->location;
                array_push($myfriend, $friend_list);

            }

           }
       } 

  $newarray = json_encode($myfriend);

'

javascript

<script>
var obj1 = JSON.parse('<?php echo $newarray ;?>');

console.log(obj1); // am not getting anything in console
</script>

EDITED

output from echo $newarray;

[
    {
        "id": 50393960,
        "screen_name": "BillGates",
        "name": "Bill Gates",
        "profile_image_url": "http://pbs.twimg.com/profile_images/1884069342/BGtwitter_normal.JPG",
        "location": "Seattle, WA"
    },
    {
        "id": 141527741,
        "screen_name": "prakashraaj",
        "name": "Prakash Raj",
        "profile_image_url": "http://pbs.twimg.com/profile_images/2951815972/ab32fb806b480d0dc761805ae4ef9775_normal.jpeg",
        "location": "india"
    },
    {
        "id": 88856792,
        "screen_name": "aamir_khan",
        "name": "Aamir Khan",
        "profile_image_url": "http://pbs.twimg.com/profile_images/2254031972/_MG_2190_normal.jpeg",
        "location": "Mumbai"
    },
    {
        "id": 107318424,
        "screen_name": "bipsluvurself",
        "name": "Bipasha Basu",
        "profile_image_url": "http://pbs.twimg.com/profile_images/419745345178832896/8JvqwEM9_normal.jpeg",
        "location": "Mumbai, India"
    }
]

Please help, am stuck with this

In the absence of information about how you validated json array, this is what I can recommend. Change your javascript to:

<script>
var jsonString = '<?php echo $newarray ;?>';
console.log(jsonString);
var obj1 = JSON.parse(jsonString);
console.log(obj1); // am not getting anything in console
</script>

You can see the content of jsonString in the javascript console. That should give you hints about what is going wrong.

Note:You are fetching JSON content from twitter, converting it to PHP data structure and converting it back to JSON. Sending the JSON string from twitter to javascript is far more efficient - if there is no need to filter/alter the twitter returned data.

You can directly output the json:

Change to:

var obj1 = <?php echo $newarray ;?>;

For example:

<?php
$newarray = json_encode(array('name' => 'srain'));
?>
var obj1 = <?php echo $newarray ;?>;

It will output:

  var obj1 = {"name":"srain"};

update

If your js script is not in the same file with the php code, the $newarray will be null.