Guest User

Untitled

a guest
Feb 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. "{"description":"Testing","site":"http://localhost","steps":{"step":[{"command":"grabimage","parameter":"img[alt="Next"]"},{"command":"click","parameter":"img[alt="Previous"]"}]}}"
  2.  
  3. <?xml version="1.0"?>
  4. <pullcase>
  5. <description>Testing</description>
  6. <site>http://localhost:81</site>
  7. <steps>
  8. <step>
  9. <command>grabimage</command>
  10. <parameter>img[alt="Next"]</parameter>
  11. </step>
  12. </steps>
  13. </pullcase>
  14.  
  15. ["steps"]=>
  16. array(1) {
  17. ["step"]=>
  18. array(2) {
  19. ["command"]=>
  20. string(9) "grabimage"
  21. ["parameter"]=>
  22. string(15) "img[alt="Next"]"
  23. }
  24. }
  25.  
  26. ["steps"]=>
  27. array(1) {
  28. ["step"]=>
  29. array(2) {
  30. [0]=>
  31. array(2) {
  32. ["command"]=>
  33. string(9) "grabimage"
  34. ["parameter"]=>
  35. string(15) "img[alt="Next"]"
  36. }
  37. [1]=>
  38. array(2) {
  39. ["command"]=>
  40. string(5) "click"
  41. ["parameter"]=>
  42. string(19) "img[alt="Previous"]"
  43. }
  44. }
  45. }
  46.  
  47. ["steps"]=>
  48. array(1) {
  49. ["step"]=>
  50. array(1) {
  51. [0]=>
  52. array(2) {
  53. ["command"]=>
  54. string(9) "grabimage"
  55. ["parameter"]=>
  56. string(15) "img[alt="Next"]"
  57. }
  58. }
  59.  
  60. $json = <<<'JSON'
  61. {
  62. "key": {
  63. "list_example": [
  64. {
  65. "key": "value"
  66. }
  67. ]
  68. }
  69. }
  70. JSON;
  71.  
  72. var_dump(json_decode($json));
  73.  
  74. object(stdClass)#1 (1) {
  75. ["key"]=>
  76. object(stdClass)#2 (1) {
  77. ["list_example"]=>
  78. array(1) {
  79. [0]=>
  80. object(stdClass)#3 (1) {
  81. ["key"]=>
  82. string(5) "value"
  83. }
  84. }
  85. }
  86. }
  87.  
  88. $json='{"description":"Testing","site":"http:\/\/localhost","steps":{"step":{"command":"grabimage","parameter":"img[alt=\"1Next\"]"}}}';
  89. $array=json_decode($json,true);
  90. if(key($array['steps']['step'])==='command'){ // if first key is "command" it is not indexed (in other words, "lone")
  91. $array['steps']['step']=[$array['steps']['step']]; // position the lone subarray (deeper) in an indexed subarray.
  92. }
  93. var_export($array);
  94.  
  95. array (
  96. 'description' => 'Testing',
  97. 'site' => 'http://localhost',
  98. 'steps' =>
  99. array (
  100. 'step' =>
  101. array (
  102. 0 =>
  103. array (
  104. 'command' => 'grabimage',
  105. 'parameter' => 'img[alt="1Next"]',
  106. ),
  107. ),
  108. ),
  109. )
Add Comment
Please, Sign In to add comment