Solved

Parse a response returned from post  with coldfusion (struct)

Posted on 2011-02-25
7
298 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
DevOps Toolchain Recommendations

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

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

22 Experts available now in Live!

Get 1:1 Help Now