cbeverly
asked on
coldfusion variables
I have a URL query parameter string that is:
?fq=object_type:"Graphic+a rts"&rows% 3D10&q%3Dc atlin%26
I want it to be
?fq=object_type:"Graphic+a rts"&rows= 10&q=catli n
Is there a way to do this without replacing text.
I tried URLDecode but it didn't work.
Thanks.
?fq=object_type:"Graphic+a
I want it to be
?fq=object_type:"Graphic+a
Is there a way to do this without replacing text.
I tried URLDecode but it didn't work.
Thanks.
What result did you get? Because it works fine for me
Hey try using 'unescape()' javascript function.
You can also refer below link:
http://www.w3schools.com/jsref/jsref_unescape.asp
You can also refer below link:
http://www.w3schools.com/jsref/jsref_unescape.asp
ASKER
My problem is I have a list below that I want to loop through using comma as a delimiter which works fine until it gets to "Catlin,George" and then it thinks there are 2 separate entities instead of one. I want the list to be separated out into 1. object_type 2. topic 3. name 4. place 5. onPhyscialExhibit and 6.culture I don't know what else to use for a delimiter.
object_type:"Paintings",to pic:"Front ier",name: "Catlin, George",place:"United States",onPhysicalExhibit: "Yes",cult ure:"India ns of North America"
object_type:"Paintings",to
CF list functions accept other delimiters besides a comma. So if you're creating the original list, you could use any delimiter you want, like "|" or "~" or even non-printable characters.
YourString
object_type:"Paintings"|to pic:"Front ier"|name: "Catlin, George"|place:"United States"|onPhysicalExhibit: "Yes"|cult ure:"India ns of North America"
Example
<cfset params = {}>
<cfloop list="#yourString#" index="elem" delimiters="|">
<cfif listLen(elem, ":") eq 2>
<cfset theName = listFirst(elem, ":")>
<cfset theValue = replace(listLast(elem, ":"), '"', "", "all")>
<cfset params[theName] = theValue>
</cfif>
</cfloop>
<cfdump var="#params#">
YourString
object_type:"Paintings"|to
Example
<cfset params = {}>
<cfloop list="#yourString#" index="elem" delimiters="|">
<cfif listLen(elem, ":") eq 2>
<cfset theName = listFirst(elem, ":")>
<cfset theValue = replace(listLast(elem, ":"), '"', "", "all")>
<cfset params[theName] = theValue>
</cfif>
</cfloop>
<cfdump var="#params#">
Even simpler, format the list values as a JSON string:
ie YourString:
{"place":"United States","name":"Catlin, George","culture":"Indians of North America","object_type":"Pa intings"," topic":"Fr ontier","o nPhysicalE xhibit":tr ue}
Then you can deserialize it into a CF structure with just:
<cfset paramsAsStruct = deserializeJSON(yourString )>
ie YourString:
{"place":"United States","name":"Catlin, George","culture":"Indians
Then you can deserialize it into a CF structure with just:
<cfset paramsAsStruct = deserializeJSON(yourString
ASKER
When I try #SerializeJson(url.fq)#
I am getting this below not the string you have. "place:\"United States\",name:\"Catlin, George\",culture:\"Indians of North America\","object_type:\"P aintings\" ,topic:\"F rontier\""
I am getting this below not the string you have. "place:\"United States\",name:\"Catlin, George\",culture:\"Indians
No assuming #url.fq# contains a json string, you want to DEserialize, not serialize. Deserializing will convert the json string back into a CF structure.
<cfset paramsAsStruct = deserializeJSON( url.fq )>
<cfset paramsAsStruct = deserializeJSON( url.fq )>
ASKER
When I try deserializeJSON(url.fq) I get this error message:
JSON parsing failure at character 1:'p' in place:"United States",culture:"Indians of North America",object_type:"Pain tings"
JSON parsing failure at character 1:'p' in place:"United States",culture:"Indians of North America",object_type:"Pain
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your help. I attacked the problem from a different approach so I am not going to use the code I posted.