开发者

php json encode outputting invalid json from mysql results [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

encode json using php?

$hello_world = $this->session->all_userdata();
foreach($hello_world as $key=>$product_id)
{
$query['products']  = $this->Global_products->globalFindProductsViewed($product_id);
    foreach($query['products'] as $product)
{
$ryan[] = $product->name;
}

}
foreach($ryan as $r) 
{
    echo json_encode(array($r));
}

The output then looks like this: ["Alpine 50W x 4 Appl开发者_如何学Pythone® iPod®-Ready In-Dash CD Deck"]

I know I cant access this with JavaScript. Can someone suggest how I can make this work?


JSON encoding every array element separately doesn't make sense.

Remove the foreach, and just do a

echo json_encode($ryan);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜