Solved

Parse a response returned from post  with coldfusion (struct)

Posted on 2011-02-25
7
296 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

8 Experts available now in Live!

Get 1:1 Help Now