Solved

Parse a response returned from post  with coldfusion (struct)

Posted on 2011-02-25
7
300 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

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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