try seeing what json_encode() creates: $json = "json"; $data = array( "no_1" => $json, "no_2" => $json, "no_3" => $json, "no_4" => array("foo" => $json, "bar" = $json), ); print_r({"{$json}_encode"}($data)); Christoph Boget wrote: > The string used below in "$myArrEncoded" is generated in javascript, after > creating the structure and spitting out: > > var JSONVar = javascriptVar.toSource(); > > I can eval JSONVar and work with it as I would be working with the original > javascriptVar so I know the transition back and forth from a structure to a > string isn't causing problems. The problem is when I try to work with the > string in PHP. > > Here is my code: > > <?php > > $myArrEncoded = "({Salary:{'50-70K':{filterType:"range", > fieldName:"SALARY", fieldValueLabel:"50-70K", > lowerValue:"50", upperValue:"70", > inclusive:"BOTH"}}, > Position:{Developer:{filterType:"single", > fieldName:"POSITION", fieldValueLabel:"Developer", > fieldValue:"Developer", constraint:"equals"}, > SysAdmin:{filterType:"single", fieldName:"POSITION", > fieldValueLabel:"System Admin", fieldValue:"SysAdmin", > constraint:"equals"}}, 'Required Action':{'2 - > GenScreen':{filterType:"single", > fieldName:"REQUIRED_ACTION", fieldValueLabel:"General Phone > Screen", fieldValue:"2 - GenScreen", > constraint:"equals"}}})"; > > echo var_dump( $myArrEncoded ) . '<br><br>'; > echo '$myArr encoded: ' . $myArrEncoded . '<br><br>'; > try { > echo '$myArr decoded: <pre>' . print_r( json_decode( $myArrEncoded, TRUE > ), TRUE ) . '</pre><br><br>'; > } catch( Exception $e ) { > echo 'Error: ' . var_dump( $e ); > } > > ?> > > When I run it, I get the following output: > > -------------------------------------------------------------------------------- > > string(587) "({Salary:{'50-70K':{filterType:"range", > fieldName:"SALARY", fieldValueLabel:"50-70K", lowerValue:"50", > upperValue:"70", inclusive:"BOTH"}}, > Position:{Developer:{filterType:"single", fieldName:"POSITION", > fieldValueLabel:"Developer", fieldValue:"Developer", > constraint:"equals"}, SysAdmin:{filterType:"single", > fieldName:"POSITION", fieldValueLabel:"System Admin", > fieldValue:"SysAdmin", constraint:"equals"}}, 'Required Action':{'2 - > GenScreen':{filterType:"single", fieldName:"REQUIRED_ACTION", > fieldValueLabel:"General Phone Screen", fieldValue:"2 - GenScreen", > constraint:"equals"}}})" > > $myArr encoded: ({Salary:{'50-70K':{filterType:"range", > fieldName:"SALARY", fieldValueLabel:"50-70K", lowerValue:"50", > upperValue:"70", inclusive:"BOTH"}}, > Position:{Developer:{filterType:"single", fieldName:"POSITION", > fieldValueLabel:"Developer", fieldValue:"Developer", > constraint:"equals"}, SysAdmin:{filterType:"single", > fieldName:"POSITION", fieldValueLabel:"System Admin", > fieldValue:"SysAdmin", constraint:"equals"}}, 'Required Action':{'2 - > GenScreen':{filterType:"single", fieldName:"REQUIRED_ACTION", > fieldValueLabel:"General Phone Screen", fieldValue:"2 - GenScreen", > constraint:"equals"}}}) > > $myArr decoded: ({Salary:{'50-70K':{filterType:"range", > fieldName:"SALARY", fieldValueLabel:"50-70K", lowerValue:"50", > upperValue:"70", inclusive:"BOTH"}}, > Position:{Developer:{filterType:"single", fieldName:"POSITION", > fieldValueLabel:"Developer", fieldValue:"Developer", > constraint:"equals"}, SysAdmin:{filterType:"single", > fieldName:"POSITION", fieldValueLabel:"System Admin", > fieldValue:"SysAdmin", constraint:"equals"}}, 'Required Action':{'2 - > GenScreen':{filterType:"single", fieldName:"REQUIRED_ACTION", > fieldValueLabel:"General Phone Screen", fieldValue:"2 - GenScreen", > constraint:"equals"}}}) > > -------------------------------------------------------------------------------- > > Why isn't json_decode() converting the string to an array? Is there > something extra in there that json_decode() can't deal with? I can work > with it fine in javascript... :( > > thnx, > Christoph > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php