Converting JSON string to an array in ColdFusion MX7

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 03:04:38

问题


I have a cookie value like:

"[{"index":"1","name":"TimePeriod","hidden":false},{"index":"2","name":"Enquiries","hidden":false},{"index":"3","name":"Online","hidden":false}]"

I would like to use this cookie value as an array in ColdFusion. What would be the best possible way to do this?


回答1:


The normal answer would be use the built-in deserializeJson function, but since that function wasn't available in CFMX7 (it arrived in CF8), you will need to use a UDF to achieve the same thing.

There are two sites which contain resources of this type, cflib.org and riaforge.org, each of which have a different potential solution for MX7.

Searching CFlib provides JsonDecode. (CFLib has a specific filter for "Maximum Required CF Version", so you can ensure any results that appear will work for your version.)

Searching riaforge provides JSONUtil, which runs on MX7 (but also claims better type mapping than the newer built-in functions).

Since MX7 runs on Java, you can likely also make use of any of the numerous Java libraries listed on json.org, using createObject/java.




回答2:


JSON serialization was added natively in CF8.

If you are on MX7 look on riaforge.org for a library that will deSerialize JSON for you.



来源:https://stackoverflow.com/questions/14321008/converting-json-string-to-an-array-in-coldfusion-mx7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!