Solved

coldfusion variables

Posted on 2012-04-03
10
187 Views
Last Modified: 2012-04-10
I have a URL query parameter string that is:
?fq=object_type:"Graphic+arts"&rows%3D10&q%3Dcatlin%26
I want it to be
?fq=object_type:"Graphic+arts"&rows=10&q=catlin
Is there a way to do this without replacing text.
I tried URLDecode but it didn't work.
Thanks.
0
Comment
Question by:cbeverly
  • 5
  • 4
10 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 37801516
What result did you get? Because it works fine for me
0
 
LVL 2

Expert Comment

by:sumCold
ID: 37805822
Hey try using 'unescape()' javascript function.

You can also refer below link:

http://www.w3schools.com/jsref/jsref_unescape.asp
0
 

Author Comment

by:cbeverly
ID: 37807895
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",topic:"Frontier",name:"Catlin, George",place:"United States",onPhysicalExhibit:"Yes",culture:"Indians of North America"
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37812564
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"|topic:"Frontier"|name:"Catlin, George"|place:"United States"|onPhysicalExhibit:"Yes"|culture:"Indians 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#">
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37812597
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":"Paintings","topic":"Frontier","onPhysicalExhibit":true}

Then you can deserialize it into a CF structure with just:

             <cfset paramsAsStruct = deserializeJSON(yourString)>
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:cbeverly
ID: 37824627
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:\"Paintings\",topic:\"Frontier\""
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37824761
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 )>
0
 

Author Comment

by:cbeverly
ID: 37825040
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:"Paintings"
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 37825122
It'll only work IF you changed the url string to pass a JSON string for the #url.fq# parameter. (It won't work with your original value because it's not a valid json string. )  If you are passing a json string, then make sure you urlencoded the value:

            ie   somePage.cfm?fq=#URLEncodedFormat(serializeJSON(someStruct))#"

If you can't change it to pass JSON, you'll have to use the 1st approach instead.
0
 

Author Closing Comment

by:cbeverly
ID: 37828469
Thank you for your help. I attacked the problem from a different approach so I am not going to use the code I posted.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now