Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Does JSON like any specific array structure?

when it is used in

$value['date'][0] = "12-21-2012";
$value['name'][1] = "Joe";
echo json_encode($value);

it seems to detect JSON under firebug

however, when it is switched around firebug does not seem to see it as JSON

$value[0]['date'] = "12-21-2012";
$value[1]['name'] = "Joe";
echo json_encode($value);

is it behaving normally?

share|improve this question
    
The first one becomes an object and the second is an array. That'd shouldn't be an issue, but they are not the same structure, so you need to access them differently. What do the 2 echo when you json_encode them? –  Rocket Hazmat Jul 17 '13 at 19:37
    
Thanks! Been using echo json_encode($value) for most of the time now. under PHP it does not seem to output the actual JSON data if you do not add "echo" command. it basically outputs the data with echo command –  Bigs Jul 17 '13 at 19:45
    
json_encode just returns a string. If you don't echo it, it doesn't get displayed. –  Rocket Hazmat Jul 17 '13 at 19:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.