-5

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 Apple® iPod®-Ready In-Dash CD Deck"]

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

7
  • The output looks fine to me. What do you believe the problem is? Commented Sep 24, 2011 at 15:29
  • I think I will have a problem accessing it via ajax Commented Sep 24, 2011 at 15:30
  • 4
    You think? Have you even tried? Commented Sep 24, 2011 at 15:30
  • No because I know that in order to access the data it has to be in a certain format. Commented Sep 24, 2011 at 15:32
  • Like this format: [{"hello":"Rand McNally Soft Case for Most 5\" GPS"},{"hello":"Rand McNally Hard Case for Most 5\" GPS"} Commented Sep 24, 2011 at 15:34

1 Answer 1

1

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

Remove the foreach, and just do a

echo json_encode($ryan);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.