Copy link to clipboard
Copied
I am relatively new to working with JSON. I've had success with a few projects reusing the same code. On this particular one, the JSON data is returned differently and I could use some assistance on my deserialize code. This what I've been using:
<cfset requestBody = toString( getHttpRequestData().content ) />
<cfset results = deserializeJSON( requestBody )>
This is what I get back when I dump the reply:
I assume my toString is looking at the wrong location for the response since the requestBody is empty.
Appreciate any help!
Thanks,
Gary
Yes, that's the one: cfhttp.filecontent. An alternative way is to use the attribute result="httpResult" in the cfhttp tag, then proceed as before with
<cfset results = deserializeJSON(httpResult.filecontent)>
Incidentally, as you're processing cfhttp, it means you have made an HHTP request to a server. You are therefore a client. The function you originally used, getHttpRequestData(), is server code. For example, if you use cfhttp and cfhttpparam to post a form to the server, getHttpRequestData
...Copy link to clipboard
Copied
Hello, ghanna1,
I haven't worked much with JSON, but it seems to me that the issue isn't in how the JSON is received, but rather how it's sent. If the requestbody is empty, then whatever is sending the JSON would have an issue. At least, that's how I perceive it. Check whatever is sending the JSON.
V/r,
^ _ ^
Copy link to clipboard
Copied
I probably should have mentioned the response I am expecting is shown in the Filecontent of the cfdump image I attached. That's why I assumed my toString command was looking for the response in the wrong place.
Gary
Copy link to clipboard
Copied
AFAIK, the method you're using for getting the JSON is what I've used. And it should be in the REQUESTBODY. Which is why I think it's the way it's being SENT is the issue. Perhaps this SO thread could provide some solution.
HTH,
^ _ ^
Copy link to clipboard
Copied
Thanks for the link. I poked around SO and found this thread. I needed to change to this:
<cfset results = deserializeJSON( cfhttp.filecontent )>
Appreciate the help!
Gary
Copy link to clipboard
Copied
Yes, that's the one: cfhttp.filecontent. An alternative way is to use the attribute result="httpResult" in the cfhttp tag, then proceed as before with
<cfset results = deserializeJSON(httpResult.filecontent)>
Incidentally, as you're processing cfhttp, it means you have made an HHTP request to a server. You are therefore a client. The function you originally used, getHttpRequestData(), is server code. For example, if you use cfhttp and cfhttpparam to post a form to the server, getHttpRequestData() will enable the server to get the request data.
Copy link to clipboard
Copied
Please read "HTTP request" in place of "HHTP request".
(the "More" editing button doesn't seem to work)