XPRIM_RandomAccessJsonReader and ReadStringWithName

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
jan
Posts: 9
Joined: Thu Sep 06, 2018 12:36 pm

XPRIM_RandomAccessJsonReader and ReadStringWithName

Post by jan » Sat Jan 26, 2019 5:10 pm

Hi. I have been trying to use XPRIM_RandomAccessJsonReader to read through the JSON object coming from an HttpResponse below:

Code: Select all

{
    "operation": {
        "result": {
            "message": "Request details added successfully.",
            "status": "Success"
        }
     }
}
According to the documentation, it seemed like the RandomAccessJSONReader would have allowed me to read through objects without having to go through from the Root Path. So what I did was this below:

Code: Select all

Define_Com Class(#XPRIM_RandomAccessJsonReader) Name(#JsonRandomAccessReader) 
Define_Com Class(#XPRIM_ErrorInfo) Name(#JsonErrorInfo)

#JsonRandomAccessReader.SetSourceHttpResponse Httpresponse(#HttpRequest.Response) Errorinfo(#JsonErrorInfo)

#JsonRandomAccessReader.BeginObjectWithName( "result" )

#oErrorCode := #JsonRandomAccessReader.ReadStringWithName( "status" "" #STD_TEXT ).AsNativeString

#JsonRandomAccessReader.EndObject
The BeginObjectWithName seems to work and says that there is one child under "result". However the ReadStringWithName part always ends with a not found status.

I was able to make this work by using #JsonRandomAccessReader.ReadStringWIthPath( 'operation/result/status' '' #STD_TEXT ).asNativeString instead but would like to understand why the ReadStringWIthName code did not work.

Thank you in advance for any information.

tsupartono
Posts: 74
Joined: Wed Jan 25, 2017 11:12 am

Re: XPRIM_RandomAccessJsonReader and ReadStringWithName

Post by tsupartono » Thu Jan 31, 2019 5:53 pm

Since the result property is under the operation object, I would imagine you would need to start from operation, followed by result?

Code: Select all

#JsonRandomAccessReader.BeginObjectWithName( "operation" )
#JsonRandomAccessReader.BeginObjectWithName( "result" )
Or you can also do:

Code: Select all

#JsonRandomAccessReader.BeginObjectWithPath( "operation/result" )

jan
Posts: 9
Joined: Thu Sep 06, 2018 12:36 pm

Re: XPRIM_RandomAccessJsonReader and ReadStringWithName

Post by jan » Wed Feb 06, 2019 6:54 pm

@tsupartono thanks for the response. That is what I did eventually and it did work.

However, I thought there was a way for the reader to read specific strings without having to specify the paths or objects.

Post Reply