4

I am converting an array to json from php json_encode(). If I encode it for one array I can decode it, but when it is like this:array('a'=>array(0=>array(),1=>array())) it returns {"a":[[],[]]}

When I decode it I get the following error

Catchable fatal error: Object of class stdClass could not be converted to string

json source

the json is here

3
  • you try to echo the json_decode result. Commented Feb 5, 2013 at 10:31
  • 1
    always validate your json data using http://jsonlint.com/ Commented Feb 5, 2013 at 10:34
  • json is fine thats not an issue Commented Feb 5, 2013 at 10:37

2 Answers 2

12

use true as second parameter in json_decode

$arr = json_decode($your_array,true); // it will create array

working example http://codepad.viper-7.com/0Dxxm8

Sign up to request clarification or add additional context in comments.

2 Comments

any idea how to do it in json.parse ??
there is my json its returning valid json.parser.online.fr here but not parsing in neither php nor javascript
0

This is valid json and working too It is already a json so no need to parse this json

var json={};//copy json from http://pastebin.com/rLw4ABwS

console.log(json);

Test the code on fiddle http://jsfiddle.net/rRNSN/

Check in console it returns as an object means it is valid json, If it will be a string then it needs to be parse using JSON.parse() or by jquery.parseJSON().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.