Hi
I'm trying to read a response back from a web service using
Define_Com Class(#PRIM_JSON.Document) Name(#lDocument)
#UniCodeString := #Request.Response.AsString.Trim
#lDocument.LoadFromString( #UniCodeString )
#msgdta := #lDocument.RootNode<'MESSAGE'>.AsString
Which is great if I get valid json. However, in some circumstances the service returns a valid response (200) but the content is a HTML error page. When this hits the LoadFromString the application ends immediately with no error messages. There seems to be no error handling available in #PRIM_JSON.Document and the response is not null.
Does any one know how I can handle this properly.
(I'm using #PRIM stuff rather than the more widely documented #XPRIM because its much faster. In this case I could probably go with #XPRIM but I'd like to stick with this.)
Reading JSON
Re: Reading JSON
Jim,
try something like:
Or even see the value of #Request.Response.ContentType (if it doesnt contain JSON this should tell you).
try something like:
Code: Select all
Define_Com Class(#PRIM_JSON.Document) Name(#lDocument)
#UniCodeString := #Request.Response.AsString.Trim
#lDocument.LoadFromString( #UniCodeString )
if (#Document.isObject) << returns false if not a JSON object...
#msgdta := #lDocument.RootNode<'MESSAGE'>.AsString
Endif
Code: Select all
if (#Request.Response.ContentType.UpperCase.Contains('JSON'))
... do your doc load
else
... error message?
endif
-
jimwatterson
- Posts: 56
- Joined: Thu Jul 09, 2020 8:31 am
Re: Reading JSON
Thanks Brendan. Sage words!
Cheers
Jim
Cheers
Jim