Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Parse a response returned from post  with coldfusion (struct)

Posted on 2011-02-25
7
Medium Priority
?
309 Views
Last Modified: 2012-05-11
This is what is being returned from my post. I need to extract the elements and set vars below.
<cfset status = ???>
<cfset message = ???>
<cfset request =????>

Any help appreciates.


This is whats returned;

Charsetutf-8
ErrorDetail[empty string]
Filecontent<result><status>Success</status><message>195</message><request>63</request></result>
HeaderHTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Date: Fri, 25 Feb 2011 17:28:05 GMT Cache-Control: private X-AspNet-Version: 2.0.50727 Content-Length: 84 Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET
Mimetypetext/html
Responseheaderstruct
Cache-Controlprivate
Content-Length84
Content-Typetext/html; charset=utf-8
DateFri, 25 Feb 2011 17:28:05 GMT
ExplanationOK
Http_VersionHTTP/1.1
ServerMicrosoft-IIS/6.0
Status_Code200
X-AspNet-Version2.0.50727
X-Powered-ByASP.NET

Statuscode200 OK
TextYES


God Bless.
0
Comment
Question by:LeadCo
  • 4
  • 3
7 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 34981680
<!--- parse it into xml --->
<cfset xml = xmlParse( CFHTTP.Filecontent )>

<!--- grab the values --->
<cfset status = xml.result.status.xmlText>
<cfset message = xml.result.message.xmlText>
<cfset request = xml.result.request.xmlText>
0
 

Author Comment

by:LeadCo
ID: 34982640
Thanks!
 I included the code and when i return back as json string to Jquery I get this: {"MESSAGE":1514,"REQUEST":{"cfdumpinited":false},"STATUS":"Success"},

Notice the Request is cfdumpinited: false  . Its supposed to be anumber.

Any suggestions?

0
 
LVL 52

Expert Comment

by:_agx_
ID: 34982697
Not sure how you're serializing, but this works for me

<cfset data.status = xml.result.status.xmlText>
<cfset data.message = xml.result.message.xmlText>
<cfset data.request = xml.result.request.xmlText>
<cfoutput>#serializeJSON(data)#</cfoutput>
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 

Author Comment

by:LeadCo
ID: 34982816
I am just returning as a struct to Jquery.

<cfset status = xml.result.status.xmlText>
<cfset message = xml.result.message.xmlText>
<cfset request = xml.result.request.xmlText>
<cfset returnStruct.message = message>
 <cfset returnStruct.status = status>
 <cfset returnStruct.request = request>

Then when i alert it.

var strIDO = JSON.stringify(DataOBJ);
alert(strIDo)

I get


{"MESSAGE":1514,"REQUEST":{"cfdumpinited":false},"STATUS":"Success"},

0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 2000 total points
ID: 34982868
<cfset returnStruct.request = request>

Well request is a reserved word. Perhaps using it as a variable name is causing a problem. Try using another name instead

<cfset requestValue = xml.result.request.xmlText>
...
<cfset returnStruct.request = requestValue>
0
 

Author Comment

by:LeadCo
ID: 34984141
Thanks!
0
 

Author Closing Comment

by:LeadCo
ID: 34984161
Thanks for the help.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

926 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