Get string value of array on remote server - php

I'm trying to find the content of an array on a remote server. All I can send back currently is strings (due to limitations in the PHP implementation of xmlrpc). Normally, I'd just use var_dump(), but that returns void. I've tried using var_export, but I get XML errors, even when I cast the result to a string.
How can I get the string representation of an array?

Use serialize():
$string = serialize( $array);
Then use unserialize() to get it back into an array:
$array = unserialize( $string);
You can also use json_encode() / json_decode() if you're interested in a JSON formatted string.
$string = json_encode( $array);
$array = json_decode( $string);

You can use PHP serialize, json_encode .... These are alternate methods to encode an object.

Related

Serilaizing in PHP returns wrong value

I try to serialize my data with PHP. Unfortunaly, the serialize() function returns a wrong value.
String to be serialized:
{"2c4cfd9a340dd0dc88b5712c680c1f88":{"type":"product_custom","layout":"default","size":"medium_large","attributes":{"62d7d5184b7a313dc64255bdb8187847":{"type":"image","color":"#FFFFFF","image":"36018"}}}}
What serialize() returns on my server:
serialize($code);
s:204:"{"2c4cfd9a340dd0dc88b5712c680c1f88":{"type":"product_custom","layout":"default","size":"medium_large","attributes":{"62d7d5184b7a313dc64255bdb8187847":{"type":"image","color":"#FFFFFF","image":"36018"}}}}";
What should be returned (https://duzun.me/playground/serialize):
a:1:{s:32:"2c4cfd9a340dd0dc88b5712c680c1f88";a:4:{s:4:"type";s:14:"product_custom";s:6:"layout";s:7:"default";s:4:"size";s:12:"medium_large";s:10:"attributes";a:1:{s:32:"62d7d5184b7a313dc64255bdb8187847";a:3:{s:4:"type";s:5:"image";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:5:"36018";}}}}
You need to json_decode it first to get the wanted result:
When you use the boolean switch as second parameter in json_decode it will be an array instead of an object.
$serialized = serialize(json_decode($inputString, true));
echo $serialized;
// output:
// a:1:{s:32:"2c4cfd9a340dd0dc88b5712c680c1f88";a:4:{s:4:"type";s:14:"product_custom";s:6:"layout";s:7:"default";s:4:"size";s:12:"medium_large";s:10:"attributes";a:1:{s:32:"62d7d5184b7a313dc64255bdb8187847";a:3:{s:4:"type";s:5:"image";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:5:"36018";}}}}
The site you're using isn't clear about what it's doing, but it appears to be treating the string as JSON and decoding to an array before serializing it as PHP. If you want to replicate this, you can use:
$str = '{"2c4cfd9a340dd0dc88b5712c680c1f88":{"type":"product_custom","layout":"default","size":"medium_large","attributes":{"62d7d5184b7a313dc64255bdb8187847":{"type":"image","color":"#FFFFFF","image":"36018"}}}}';
echo serialize(json_decode($str, true));
a:1:{s:32:"2c4cfd9a340dd0dc88b5712c680c1f88";a:4:{s:4:"type";s:14:"product_custom";s:6:"layout";s:7:"default";s:4:"size";s:12:"medium_large";s:10:"attributes";a:1:{s:32:"62d7d5184b7a313dc64255bdb8187847";a:3:{s:4:"type";s:5:"image";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:5:"36018";}}}}
As pointed out in the comments, unless there's a specific reason you need serialized PHP, then just stick with the serialized JSON string you already have - it'll be both more readable and portable.

Converting string-array to an array of strings

I am struggling with converting a string into an array:
["Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"]
and I want to convert it into an array of values inside quotes "".
Tried (un)serialize(), parse_str(). They don't cope with it.
Since nobody else is going to post it, that looks like JSON:
$array = json_decode($string, true);
print_r($array);
The true parameter isn't needed for this JSON, but if you want to make sure you always get an array and not an object regardless of the JSON then use it.
It would be easiest to use json_decode:
json_decode('["Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"]', true)
But if for some reason you are not parsing is as json, you should be able to use explode:
explode(',', '"Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"');
If you need to deal with the brackets, you can trim them from the string with something like this prior to exploding:
$string = trim('["Пятницкое шоссе","Митино","Волоколамская","Планерная","Сходненская"]', '[]');

How to parse a json object into a url parameter string in PHP?

I have the following json encoded object:
{"username":"my_username","email":"my_email","password":"12345678","confirm_password":"12345678"}
and I want to convert this into url string so I can use it with my REST API function for example like this one:
search?search=asdadd%2C+United+Kingdom&type=tutor
I have found many functions in javascript to do this but I haven't been able to find anything in PHP. What is the function in PHP to do this?
The following query string:
?username=my_username&email=my_email&password=12345678&confirm_password=12345678
.. will turn into:
{"username":"my_username","email":"my_email","password":"12345678","confirm_password":"12345678"}
If you use json_enconde.
To reverse the process, you need to use json_decode as well as http_build_query.
First, turn the JSON into an associative array with json_decode:
$json = '{"username":"my_username","email":"my_email","password":"12345678","confirm_password":"12345678"}';
$associativeArray = json_decode($json, true);
Now use http_build_query with the new associative array we've built:
$queryString = http_build_query($associativeArray);
Result: username=my_username&email=my_email&password=12345678&confirm_password=12345678.

json_decode not working on string variable

I'm trying to decode a json string into a php array and I'm getting a syntax error (4) when I use json_last_error().
The string comes from an API call to an Infusionsoft database. The database returns an array with one key/value pair. The value contains the json string.
Array ( [_PMSChargeItems] => [{"Date":"2012-09-07T00:00:00","Amount":0.0},{"Date":"2012-09-07T00:00:00","Amount":41.0},{"Date":"2012-09-07T00:00:00","Amount":64.0},{"Date":"2012-09-11T00:00:00","Amount":80.0},{"Date":"2012-09-11T00:00:00","Amount":474.0},{"Date":"2012-09-19T00:00:00","Amount":82.0},{"Date":"2012-09-19T00:00:00","Amount":125.0},{"Date":"2012-09-19T00:00:00","Amount":127.0},{"Date":"2012-09-19T00:00:00","Amount":174.0},{"Date":"2012-09-19T00:00:00","Amount":343.0},{"Date":"2012-09-19T00:00:00","Amount":618.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-27T00:00:00","Amount":0.0},{"Date":"2012-10-02T00:00:00","Amount":0.0},{"Date":"2012-10-02T00:00:00","Amount":0.0},{"Date":"2012-10-10T00:00:00","Amount":0.0},{"Date":"2012-11-07T00:00:00","Amount":0.0},{"Date":"2012-11-19T00:00:00","Amount":64.0},{"Date":"2012-12-21T00:00:00","Amount":0.0},{"Date":"2013-02-01T00:00:00","Amount":0.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":625.0},{"Date":"2013-02-01T00:00:00","Amount":625.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-13T00:00:00","Amount":0.0},{"Date":"2013-02-18T00:00:00","Amount":0.0},{"Date":"2013-02-25T00:00:00","Amount":65.0},{"Date":"2013-02-25T00:00:00","Amount":85.0},{"Date":"2013-03-11T00:00:00","Amount":0.0},{"Date":"2013-03-14T00:00:00","Amount":0.0},{"Date":"2013-03-14T00:00:00","Amount":0.0},{"Date":"2013-03-20T00:00:00","Amount":240.0},{"Date":"2013-06-12T00:00:00","Amount":0.0},{"Date":"2013-07-23T00:00:00","Amount":0.0},{"Date":"2013-07-26T00:00:00","Amount":0.0},{"Date":"2013-08-23T00:00:00","Amount":0.0},{"Date":"2013-09-09T00:00:00","Amount":0.0},{"Date":"2014-08-04T00:00:00","Amount":0.0},{"Date":"2014-08-11T00:00:00","Amount":30.0},{"Date":"2014-08-11T00:00:00","Amount":66.0},{"Date":"2014-08-11T00:00:00","Amount":85.0},{"Date":"2014-09-02T00:00:00","Amount":0.0},{"Date":"2014-12-16T00:00:00","Amount":0.0},{"Date":"2015-01-09T00:00:00","Amount":0.0},{"Date":"2015-02-10T00:00:00","Amount":14.0},{"Date":"2015-02-10T00:00:00","Amount":16.0},{"Date":"2015-02-10T00:00:00","Amount":43.0},{"Date":"2015-02-10T00:00:00","Amount":130.0},{"Date":"2015-02-10T00:00:00","Amount":130.0},{"Date":"2015-02-10T00:00:00","Amount":250.0},{"Date":"2015-02-10T00:00:00","Amount":640.0},{"Date":"2015-02-23T00:00:00","Amount":0.0},{"Date":"2015-02-25T00:00:00","Amount":0.0},{"Date":"2015-02-25T00:00:00","Amount":0.0},{"Date":"2015-03-26T00:00:00","Amount":0.0},{"Date":"2015-05-21T00:00:00","Amount":0.0}] )
When I save the value to a string variable and pass it to json_decode() I get the syntax error (it doesn't work). If I pass the entire json string itself (copy and paste from echoing the string var value) to json_decode() the array is created (it works).
I have validated the json string at both http://jsonlint.com/ and http://www.functions-online.com/json_decode.html.
How can I get the string to be correctly decoded when it is passed to the json_decode function using a variable?
Here's the code I am using to decode:
$cid = $_GET['Id'];
$returnFields = array('_PMSChargeItems');
$conDat = $appConnect->dsLoad("Contact", $cid, $returnFields);
$a = $conDat['_PMSChargeItems'];
var_dump(json_decode($a, true));
echo json_last_error();
Here's the result of var_dump($a) before the decode:
string(4649) "[{"Date":"2012-09-07T00:00:00","Amount":0.0},{"Date":"2012-09-07T00:00:00","Amount":41.0},{"Date":"2012-09-07T00:00:00","Amount":64.0},{"Date":"2012-09-11T00:00:00","Amount":80.0},{"Date":"2012-09-11T00:00:00","Amount":474.0},{"Date":"2012-09-19T00:00:00","Amount":82.0},{"Date":"2012-09-19T00:00:00","Amount":125.0},{"Date":"2012-09-19T00:00:00","Amount":127.0},{"Date":"2012-09-19T00:00:00","Amount":174.0},{"Date":"2012-09-19T00:00:00","Amount":343.0},{"Date":"2012-09-19T00:00:00","Amount":618.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-27T00:00:00","Amount":0.0},{"Date":"2012-10-02T00:00:00","Amount":0.0},{"Date":"2012-10-02T00:00:00","Amount":0.0},{"Date":"2012-10-10T00:00:00","Amount":0.0},{"Date":"2012-11-07T00:00:00","Amount":0.0},{"Date":"2012-11-19T00:00:00","Amount":64.0},{"Date":"2012-12-21T00:00:00","Amount":0.0},{"Date":"2013-02-01T00:00:00","Amount":0.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":625.0},{"Date":"2013-02-01T00:00:00","Amount":625.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-13T00:00:00","Amount":0.0},{"Date":"2013-02-18T00:00:00","Amount":0.0},{"Date":"2013-02-25T00:00:00","Amount":65.0},{"Date":"2013-02-25T00:00:00","Amount":85.0},{"Date":"2013-03-11T00:00:00","Amount":0.0},{"Date":"2013-03-14T00:00:00","Amount":0.0},{"Date":"2013-03-14T00:00:00","Amount":0.0},{"Date":"2013-03-20T00:00:00","Amount":240.0},{"Date":"2013-06-12T00:00:00","Amount":0.0},{"Date":"2013-07-23T00:00:00","Amount":0.0},{"Date":"2013-07-26T00:00:00","Amount":0.0},{"Date":"2013-08-23T00:00:00","Amount":0.0},{"Date":"2013-09-09T00:00:00","Amount":0.0},{"Date":"2014-08-04T00:00:00","Amount":0.0},{"Date":"2014-08-11T00:00:00","Amount":30.0},{"Date":"2014-08-11T00:00:00","Amount":66.0},{"Date":"2014-08-11T00:00:00","Amount":85.0},{"Date":"2014-09-02T00:00:00","Amount":0.0},{"Date":"2014-12-16T00:00:00","Amount":0.0},{"Date":"2015-01-09T00:00:00","Amount":0.0},{"Date":"2015-02-10T00:00:00","Amount":14.0},{"Date":"2015-02-10T00:00:00","Amount":16.0},{"Date":"2015-02-10T00:00:00","Amount":43.0},{"Date":"2015-02-10T00:00:00","Amount":130.0},{"Date":"2015-02-10T00:00:00","Amount":130.0},{"Date":"2015-02-10T00:00:00","Amount":250.0},{"Date":"2015-02-10T00:00:00","Amount":640.0},{"Date":"2015-02-23T00:00:00","Amount":0.0},{"Date":"2015-02-25T00:00:00","Amount":0.0},{"Date":"2015-02-25T00:00:00","Amount":0.0},{"Date":"2015-03-26T00:00:00","Amount":0.0},{"Date":"2015-05-21T00:00:00","Amount":0.0}]"
I've tried to find hidden characters using html_entities and html_entity_decode and didn't find any. I also confirmed using mb_detect_encoding that the string has all ASCII characters.
I just tried the following:
var_dump(json_decode(strval($a), true));
The result was NULL and the decode error was the syntax error.
What's curious is that var_dump on ($a) gives me a character count of 4649 whereas strlen('[("Date"....) of the string itself gives a character count of 2789...
Thanks to all of your help I solved the puzzle!
When the JSON string was returned from the Infusionsoft database all of the quotes were being stored as $quot; instead of as double quotation marks.
I found this out by saving the string to a .txt file (using fopen, fwrite, and fclose) and opening the file with a text editor. I had been figuring that I would need to look at the file with a hex editor (as was recommended by Ryan - I think that's his name anyway, he deleted his comment that contained the suggestion so I'm not sure) but it turns out that wasn't necessary. Here's what the data looked like in the file:
[{"Date":"2012-09-07T00:00:00","Amount":0.0},{"Date":"2012-09-07T00:00:00","Amount":41.0},{"Date":"2012-09-07T00:00:00","Amount":64.0},....
To remove the quotes I used htmlspecialchars_decode() on the string and then was able to successfully pass the string into json_decode. Here's the code:
$a = $conDat['_PMSChargeItems'];
$b = htmlspecialchars_decode($a);
$c = json_decode($b);
Thanks again for your helpful comments and answers!
EDIT
You are calling json_decode on an array that isn't json encoded, you need to call json_decode on the string that is json_encoded, i.e. the element "_PMSChargeItems" of $a
This seems to work:
$a = '[{"Date":"2012-09-07T00:00:00","Amount":0.0},{"Date":"2012-09-07T00:00:00","Amount":41.0},{"Date":"2012-09-07T00:00:00","Amount":64.0},{"Date":"2012-09-11T00:00:00","Amount":80.0},{"Date":"2012-09-11T00:00:00","Amount":474.0},{"Date":"2012-09-19T00:00:00","Amount":82.0},{"Date":"2012-09-19T00:00:00","Amount":125.0},{"Date":"2012-09-19T00:00:00","Amount":127.0},{"Date":"2012-09-19T00:00:00","Amount":174.0},{"Date":"2012-09-19T00:00:00","Amount":343.0},{"Date":"2012-09-19T00:00:00","Amount":618.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-27T00:00:00","Amount":0.0},{"Date":"2012-10-02T00:00:00","Amount":0.0},{"Date":"2012-10-02T00:00:00","Amount":0.0},{"Date":"2012-10-10T00:00:00","Amount":0.0},{"Date":"2012-11-07T00:00:00","Amount":0.0},{"Date":"2012-11-19T00:00:00","Amount":64.0},{"Date":"2012-12-21T00:00:00","Amount":0.0},{"Date":"2013-02-01T00:00:00","Amount":0.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":625.0},{"Date":"2013-02-01T00:00:00","Amount":625.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-13T00:00:00","Amount":0.0},{"Date":"2013-02-18T00:00:00","Amount":0.0},{"Date":"2013-02-25T00:00:00","Amount":65.0},{"Date":"2013-02-25T00:00:00","Amount":85.0},{"Date":"2013-03-11T00:00:00","Amount":0.0},{"Date":"2013-03-14T00:00:00","Amount":0.0},{"Date":"2013-03-14T00:00:00","Amount":0.0},{"Date":"2013-03-20T00:00:00","Amount":240.0},{"Date":"2013-06-12T00:00:00","Amount":0.0},{"Date":"2013-07-23T00:00:00","Amount":0.0},{"Date":"2013-07-26T00:00:00","Amount":0.0},{"Date":"2013-08-23T00:00:00","Amount":0.0},{"Date":"2013-09-09T00:00:00","Amount":0.0},{"Date":"2014-08-04T00:00:00","Amount":0.0},{"Date":"2014-08-11T00:00:00","Amount":30.0},{"Date":"2014-08-11T00:00:00","Amount":66.0},{"Date":"2014-08-11T00:00:00","Amount":85.0},{"Date":"2014-09-02T00:00:00","Amount":0.0},{"Date":"2014-12-16T00:00:00","Amount":0.0},{"Date":"2015-01-09T00:00:00","Amount":0.0},{"Date":"2015-02-10T00:00:00","Amount":14.0},{"Date":"2015-02-10T00:00:00","Amount":16.0},{"Date":"2015-02-10T00:00:00","Amount":43.0},{"Date":"2015-02-10T00:00:00","Amount":130.0},{"Date":"2015-02-10T00:00:00","Amount":130.0},{"Date":"2015-02-10T00:00:00","Amount":250.0},{"Date":"2015-02-10T00:00:00","Amount":640.0},{"Date":"2015-02-23T00:00:00","Amount":0.0},{"Date":"2015-02-25T00:00:00","Amount":0.0},{"Date":"2015-02-25T00:00:00","Amount":0.0},{"Date":"2015-03-26T00:00:00","Amount":0.0},{"Date":"2015-05-21T00:00:00","Amount":0.0}]';
print_r( json_decode( $a ) );
or the array way:
$a = array( '_PMSChargeItems' => '[{"Date":"2012-09-07T00:00:00","Amount":0.0},{"Date":"2012-09-07T00:00:00","Amount":41.0},{"Date":"2012-09-07T00:00:00","Amount":64.0},{"Date":"2012-09-11T00:00:00","Amount":80.0},{"Date":"2012-09-11T00:00:00","Amount":474.0},{"Date":"2012-09-19T00:00:00","Amount":82.0},{"Date":"2012-09-19T00:00:00","Amount":125.0},{"Date":"2012-09-19T00:00:00","Amount":127.0},{"Date":"2012-09-19T00:00:00","Amount":174.0},{"Date":"2012-09-19T00:00:00","Amount":343.0},{"Date":"2012-09-19T00:00:00","Amount":618.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-19T00:00:00","Amount":1122.0},{"Date":"2012-09-27T00:00:00","Amount":0.0},{"Date":"2012-10-02T00:00:00","Amount":0.0},{"Date":"2012-10-02T00:00:00","Amount":0.0},{"Date":"2012-10-10T00:00:00","Amount":0.0},{"Date":"2012-11-07T00:00:00","Amount":0.0},{"Date":"2012-11-19T00:00:00","Amount":64.0},{"Date":"2012-12-21T00:00:00","Amount":0.0},{"Date":"2013-02-01T00:00:00","Amount":0.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":470.0},{"Date":"2013-02-01T00:00:00","Amount":625.0},{"Date":"2013-02-01T00:00:00","Amount":625.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-01T00:00:00","Amount":679.0},{"Date":"2013-02-13T00:00:00","Amount":0.0},{"Date":"2013-02-18T00:00:00","Amount":0.0},{"Date":"2013-02-25T00:00:00","Amount":65.0},{"Date":"2013-02-25T00:00:00","Amount":85.0},{"Date":"2013-03-11T00:00:00","Amount":0.0},{"Date":"2013-03-14T00:00:00","Amount":0.0},{"Date":"2013-03-14T00:00:00","Amount":0.0},{"Date":"2013-03-20T00:00:00","Amount":240.0},{"Date":"2013-06-12T00:00:00","Amount":0.0},{"Date":"2013-07-23T00:00:00","Amount":0.0},{"Date":"2013-07-26T00:00:00","Amount":0.0},{"Date":"2013-08-23T00:00:00","Amount":0.0},{"Date":"2013-09-09T00:00:00","Amount":0.0},{"Date":"2014-08-04T00:00:00","Amount":0.0},{"Date":"2014-08-11T00:00:00","Amount":30.0},{"Date":"2014-08-11T00:00:00","Amount":66.0},{"Date":"2014-08-11T00:00:00","Amount":85.0},{"Date":"2014-09-02T00:00:00","Amount":0.0},{"Date":"2014-12-16T00:00:00","Amount":0.0},{"Date":"2015-01-09T00:00:00","Amount":0.0},{"Date":"2015-02-10T00:00:00","Amount":14.0},{"Date":"2015-02-10T00:00:00","Amount":16.0},{"Date":"2015-02-10T00:00:00","Amount":43.0},{"Date":"2015-02-10T00:00:00","Amount":130.0},{"Date":"2015-02-10T00:00:00","Amount":130.0},{"Date":"2015-02-10T00:00:00","Amount":250.0},{"Date":"2015-02-10T00:00:00","Amount":640.0},{"Date":"2015-02-23T00:00:00","Amount":0.0},{"Date":"2015-02-25T00:00:00","Amount":0.0},{"Date":"2015-02-25T00:00:00","Amount":0.0},{"Date":"2015-03-26T00:00:00","Amount":0.0},{"Date":"2015-05-21T00:00:00","Amount":0.0}]' );
print_r( json_decode( $a['_PMSChargeItems'] ) );
You seem to mix up JavaScript and PHP

cast string to JSON

Is there any way to make PHP look at a string as a JSON?
I have a string, in a JSON format of course, and I want to perform actions on it like it was an array. However I don't want to use CJSON::decode because it takes a long time, Is there a way?
Example for the string:
{"myArray":[{"key1":"val1","key2":"val2","key3":"val3","key4":"val4"},
{"key1":"val2_1","key2":"val2_2","key3":"val2_3","key4":"val2_4"}]}
Not sure what CJSON::decode is but you have to decode the string so you can use the built in function json_decode($str);
how about json_decode() ?
I don't think there is faster than that
$string = '{"myArray":[{"key1":"val1","key2":"val2","key3":"val3","key4":"val4"}, {"key1":"val2_1","key2":"val2_2","key3":"val2_3","key4":"val2_4"}]}';
$array = json_decode($string);

Categories