开发者

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

开发者 https://www.devze.com 2023-04-07 12:23 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: encode json using php? $hello_world = $this->session->all_userdata();
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

精彩评论

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