Reputation: 28503
I'm trying to deserialize a JSON string in Coldfusion8
. It seems to work (no errors), but I'm not able to work with the data I'm getting.
My JSON string looks like this:
"{\"kundenliste\":{\"kundennummer\":\"1\",\"plz\":\"2\",\"rabatt\":\"3\",\"laenderkennzeichen\":\"4\",\"preisliste\":\"5\...
I can do this:
<cfset variables.import = DeserializeJSON(getModus.myJSONstring)>
<cfdump output="e:\dump.txt" label="catch" var="#IsArray(variables.import)#">
<cfdump output="e:\dump.txt" label="catch" var="#IsStruct(variables.import)#">
<cfdump output="e:\dump.txt" label="catch" var="#IsObject(variables.import)#">
<cfdump output="e:\dump.txt" label="catch" var="#IsDefined(variables.import.kundenliste)#">
Results in:
{"kundenliste":{"kundennummer":"1","plz":"2","rabatt":"3","laenderkennzeich ...
NO
NO
NO
<<error>>
Question:
Am I doing something wrong when deserializing? I thought this would return a struct or array and not a string. What to do?
Thanks for help!
Upvotes: 0
Views: 956
Reputation: 28873
The original JSON string is invalid. The quotes around the name/value pairs should not be escaped like that ie \"
, which is why it is not being parsed properly. The input string should look more like your "result":
{"kundenliste":{"kundennummer":"1"}}
What is the source of that string?
Upvotes: 5