Solved

Parse a response returned from post  with coldfusion (struct)

Posted on 2011-02-25
7
304 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 500 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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