0

i am trying to decode below json string, When i var_dump or print_r the string without json_decode it works find but with decode it prints null or empty . Below is my string

$xml ='{"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>"}]"}';

if i remove the object_lightbox_io contents and try to decode string 2 times based on whole string and then on results index it gets decoded so problem is coming with object_lightbox_io can someone help me to sort this issue pls , spent hours but coudn't fix it

9
  • The value of object_lightbox_io has unescaped quotes. How is this JSON generated? Commented Dec 29, 2020 at 8:21
  • i am not sure how is it generated, getting through API call Commented Dec 29, 2020 at 8:22
  • could you please help to fix the issue e.g. fixing the un escaped quotes to sort the issue Commented Dec 29, 2020 at 8:26
  • Trying to fix this seems like a real mess, it would be better to talk to the people who generate this and they would need to fix it. Commented Dec 29, 2020 at 8:36
  • if i try to decode it online it works fine not sure how its working Commented Dec 29, 2020 at 8:41

1 Answer 1

1

The json you presented is not valid, The situation (as it should be) is that every key and value in your json is wrapped in ", "key": "value"

But within the xml there are values that break this format.

The person who sent the JSON should add a back slash to everything that exists in xml

Sign up to request clarification or add additional context in comments.

2 Comments

if i try to convert it online it works fine not sure how its working
Where did you try to decrypt the JSON and succeed? The JSON is not valid. Who sends it to you? It seems to be building the JSON incorrectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.