0

I have below JSON string. I am trying to decode and loop over it but unable to work it out. I saved json_decoded values in array and on print_r or var_dump i get Null, i also tried gettype(result) that also gives me null.

I tried online json tools it gets converted to array but for me json_decode is not working , Pls advise

Below is the string

{"pages":"3","results":"[{\"row_id\":1,\"object_id\":46740,\"created_on\":1608736483367,\"title\":\"Q By Sikander\",\"description\":\"description changed for edting\",\"subject\":\"Mathematics\",\"creator\":\"Sikander. nawaz \",\"object_lightbox_io\":\"<mxGraphModel dx=\\\"1165\\\" dy=\\\"727\\\" grid=\\\"0\\\" gridSize=\\\"10\\\" guides=\\\"1\\\" tooltips=\\\"1\\\" connect=\\\"1\\\" arrows=\\\"1\\\" fold=\\\"1\\\" page=\\\"1\\\" pageScale=\\\"1\\\" pageWidth=\\\"827\\\" pageHeight=\\\"1169\\\" math=\\\"0\\\" shadow=\\\"0\\\"><root><mxCell id=\\\"0\\\" \\/><mxCell id=\\\"1\\\" parent=\\\"0\\\" \\/><object label=\\\"\\\" Name=\\\"question\\\" id=\\\"winxapanwzodgiu_0\\\"><mxCell style=\\\"text;html=1;align=left;verticalAlign=top;whiteSpace=wrap;rounded=wrap;deletable=wrap;spacingLeft=10;spacingTop=30;strokeWidth=1;glass=0;comic=0;shadow=0;movable=1;resizable=1;strokeColor=#E6E6E6;fillColor=#FFFFFF;cloneable=0;rotatable=0;editable=1;recursiveResize=1;connectable=0;fontSize=12;fontFamily=Verdana;container=1;collapsible=0;spacing=10;allowArrows=0;expand=0;\\\" parent=\\\"1\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"40\\\" y=\\\"40\\\" width=\\\"750\\\" height=\\\"339\\\" as=\\\"geometry\\\" \\/><\\/mxCell><\\/object><mxCell id=\\\"winxapanwzodgiu_1\\\" value=\\\"Question\\\" style=\\\"rounded=0;whiteSpace=wrap;html=1;strokeColor=none;fillColor=#E8E8E8;fontSize=16;fontStyle=1;align=left;spacing=14;connectable=0;allowArrows=0;recursiveResize=0;expand=0;editable=1;movable=0;resizable=0;rotatable=0;cloneable=0;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry width=\\\"150\\\" height=\\\"30\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"RJBhnMlJpycuwUT1BXIT-1\\\" value=\\\"Text\\\" style=\\\"text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"381\\\" y=\\\"58\\\" width=\\\"40\\\" height=\\\"20\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"m-3Kp1ptq76vWhSLRoxc-1\\\" value=\\\"\\\" style=\\\"ellipse;whiteSpace=wrap;html=1;aspect=fixed;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"273\\\" y=\\\"160\\\" width=\\\"80\\\" height=\\\"80\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"xlPOsWBx98iv5f53EXYo-1\\\" value=\\\"\\\" style=\\\"shape=callout;whiteSpace=wrap;html=1;perimeter=calloutPerimeter;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"111\\\" y=\\\"222\\\" width=\\\"120\\\" height=\\\"80\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"xlPOsWBx98iv5f53EXYo-2\\\" value=\\\"\\\" style=\\\"ellipse;shape=cloud;whiteSpace=wrap;html=1;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"471\\\" y=\\\"240\\\" width=\\\"120\\\" height=\\\"80\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"xlPOsWBx98iv5f53EXYo-3\\\" value=\\\"\\\" style=\\\"whiteSpace=wrap;html=1;aspect=fixed;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"214\\\" y=\\\"90\\\" width=\\\"80\\\" height=\\\"80\\\" as=\\\"geometry\\\" \\/><\\/mxCell><\\/root><\\/mxGraphModel>\"},{\"row_id\":2,\"object_id\":48747,\"created_on\":1608854400000,\"title\":\"Updated Question \",\"description\":\"description changed for edting\",\"subject\":\"Mathematics\",\"creator\":\"Sikander. nawaz \",\"object_lightbox_io\":\"<mxGraphModel dx=\\\"810\\\" dy=\\\"631\\\" grid=\\\"0\\\" gridSize=\\\"10\\\" guides=\\\"1\\\" tooltips=\\\"1\\\" connect=\\\"1\\\" arrows=\\\"1\\\" fold=\\\"1\\\" page=\\\"1\\\" pageScale=\\\"1\\\" pageWidth=\\\"827\\\" pageHeight=\\\"1169\\\" math=\\\"0\\\" shadow=\\\"0\\\"><root><mxCell id=\\\"0\\\" \\/><mxCell id=\\\"1\\\" parent=\\\"0\\\" \\/><object label=\\\"\\\" Name=\\\"question\\\" id=\\\"winxapanwzodgiu_0\\\"><mxCell style=\\\"text;html=1;align=left;verticalAlign=top;whiteSpace=wrap;rounded=wrap;deletable=wrap;spacingLeft=10;spacingTop=30;strokeWidth=1;glass=0;comic=0;shadow=0;movable=1;resizable=1;strokeColor=#E6E6E6;fillColor=#FFFFFF;cloneable=0;rotatable=0;editable=1;recursiveResize=1;connectable=0;fontSize=12;fontFamily=Verdana;container=1;collapsible=0;spacing=10;allowArrows=0;expand=0;\\\" parent=\\\"1\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"40\\\" y=\\\"40\\\" width=\\\"750\\\" height=\\\"339\\\" as=\\\"geometry\\\" \\/><\\/mxCell><\\/object><mxCell id=\\\"winxapanwzodgiu_1\\\" value=\\\"Question\\\" style=\\\"rounded=0;whiteSpace=wrap;html=1;strokeColor=none;fillColor=#E8E8E8;fontSize=16;fontStyle=1;align=left;spacing=14;connectable=0;allowArrows=0;recursiveResize=0;expand=0;editable=1;movable=0;resizable=0;rotatable=0;cloneable=0;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry width=\\\"150\\\" height=\\\"30\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"RJBhnMlJpycuwUT1BXIT-1\\\" value=\\\"Text\\\" style=\\\"text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"381\\\" y=\\\"58\\\" width=\\\"40\\\" height=\\\"20\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"m-3Kp1ptq76vWhSLRoxc-1\\\" value=\\\"\\\" style=\\\"ellipse;whiteSpace=wrap;html=1;aspect=fixed;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"273\\\" y=\\\"160\\\" width=\\\"80\\\" height=\\\"80\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"xlPOsWBx98iv5f53EXYo-1\\\" value=\\\"\\\" style=\\\"shape=callout;whiteSpace=wrap;html=1;perimeter=calloutPerimeter;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"111\\\" y=\\\"222\\\" width=\\\"120\\\" height=\\\"80\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"xlPOsWBx98iv5f53EXYo-2\\\" value=\\\"\\\" style=\\\"ellipse;shape=cloud;whiteSpace=wrap;html=1;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"471\\\" y=\\\"240\\\" width=\\\"120\\\" height=\\\"80\\\" as=\\\"geometry\\\" \\/><\\/mxCell><mxCell id=\\\"xlPOsWBx98iv5f53EXYo-3\\\" value=\\\"\\\" style=\\\"whiteSpace=wrap;html=1;aspect=fixed;\\\" parent=\\\"winxapanwzodgiu_0\\\" vertex=\\\"1\\\"><mxGeometry x=\\\"214\\\" y=\\\"90\\\" width=\\\"80\\\" height=\\\"80\\\" as=\\\"geometry\\\" \\/><\\/mxCell><\\/root><\\/mxGraphModel>\"}]"}
ThW
  • 19,120
  • 3
  • 22
  • 44
  • looks like you’re addslashing somewhere, giving you invalid json. Your json shouldn’t have all those quotes and slashes escaped. – Tim Morton Dec 28 '20 at 14:35
  • i tried on jsonlint it sows valid json – Sikander Nawaz Dec 28 '20 at 14:37
  • It is nested. The results value is a serialized JSON string. It requires a secondary decode: `$envelope = json_decode($json); $results = json_decode($envelope->results); var_dump($results);` – ThW Dec 29 '20 at 05:58
  • @ThW i used same it gives me an error trying to access property of non-object (for results) if i remove xml from the string rest of the string woks fine – Sikander Nawaz Dec 29 '20 at 07:26

0 Answers0