Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "{"description":"Testing","site":"http://localhost","steps":{"step":[{"command":"grabimage","parameter":"img[alt="Next"]"},{"command":"click","parameter":"img[alt="Previous"]"}]}}"
- <?xml version="1.0"?>
- <pullcase>
- <description>Testing</description>
- <site>http://localhost:81</site>
- <steps>
- <step>
- <command>grabimage</command>
- <parameter>img[alt="Next"]</parameter>
- </step>
- </steps>
- </pullcase>
- ["steps"]=>
- array(1) {
- ["step"]=>
- array(2) {
- ["command"]=>
- string(9) "grabimage"
- ["parameter"]=>
- string(15) "img[alt="Next"]"
- }
- }
- ["steps"]=>
- array(1) {
- ["step"]=>
- array(2) {
- [0]=>
- array(2) {
- ["command"]=>
- string(9) "grabimage"
- ["parameter"]=>
- string(15) "img[alt="Next"]"
- }
- [1]=>
- array(2) {
- ["command"]=>
- string(5) "click"
- ["parameter"]=>
- string(19) "img[alt="Previous"]"
- }
- }
- }
- ["steps"]=>
- array(1) {
- ["step"]=>
- array(1) {
- [0]=>
- array(2) {
- ["command"]=>
- string(9) "grabimage"
- ["parameter"]=>
- string(15) "img[alt="Next"]"
- }
- }
- $json = <<<'JSON'
- {
- "key": {
- "list_example": [
- {
- "key": "value"
- }
- ]
- }
- }
- JSON;
- var_dump(json_decode($json));
- object(stdClass)#1 (1) {
- ["key"]=>
- object(stdClass)#2 (1) {
- ["list_example"]=>
- array(1) {
- [0]=>
- object(stdClass)#3 (1) {
- ["key"]=>
- string(5) "value"
- }
- }
- }
- }
- $json='{"description":"Testing","site":"http:\/\/localhost","steps":{"step":{"command":"grabimage","parameter":"img[alt=\"1Next\"]"}}}';
- $array=json_decode($json,true);
- if(key($array['steps']['step'])==='command'){ // if first key is "command" it is not indexed (in other words, "lone")
- $array['steps']['step']=[$array['steps']['step']]; // position the lone subarray (deeper) in an indexed subarray.
- }
- var_export($array);
- array (
- 'description' => 'Testing',
- 'site' => 'http://localhost',
- 'steps' =>
- array (
- 'step' =>
- array (
- 0 =>
- array (
- 'command' => 'grabimage',
- 'parameter' => 'img[alt="1Next"]',
- ),
- ),
- ),
- )
Add Comment
Please, Sign In to add comment