Quantcast
Viewing all articles
Browse latest Browse all 21760

Does cf10 change the way deserializejson handles null?

<cftry>

<cfset jsontxt="{""A"":""Bob"",""B"":123,""C"":null}">

<cfset json=deserializejson(jsontxt)>

<cfdump var="#json#">

<cfoutput>

    <li>[#structkeylist(json)#]<br>

    <li>[#json.a#]<br>

    <li>[#json.b#]<br>

    <li>[#json.c#]<br>

</cfoutput>

<cfcatch type="Any">

    <cfdump var="#cfcatch#">

</cfcatch>

</cftry>

 

The documentation states: The JSON null value becomes the string null.

http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea7785946 1172e0811cbec22c24-79e4.html

 

The above test on CF9 operates as described in the docs, but CF10 errors on #json.c#

 

I found some old code (compacted a bit), which implies that the old behavior was to convert json's null to "null".

 

<cfloop list="#structkeylist(contact)#" index="lp">

  <cfset x=evaluate("contact.#lp#")>

  <cfif x eq "null">

    <cfset "contact.#lp#"="">

  </cfif>

</cfloop>

 

This was just tested on CF10, developer edition, update 10, on Win 2008 x64 and CF9 (9.01) standard

 

In the meantime, I've added the following just after the deserializejson() command

 

<cfloop list="#structkeylist(json)#" index="lp">

    <cfparam name="json.#lp#" default="null">

</cfloop>

 

Is there another way to test for this value? Any array or structure command of some kind?

 

--Jason Miller

jmiller@quickcert.com


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>