Page 1 of 1

XPRIM_RandomAccessJsonReader and ReadStringWithName

Posted: Sat Jan 26, 2019 5:10 pm
by jan
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.

Re: XPRIM_RandomAccessJsonReader and ReadStringWithName

Posted: Thu Jan 31, 2019 5:53 pm
by tsupartono
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" )

Re: XPRIM_RandomAccessJsonReader and ReadStringWithName

Posted: Wed Feb 06, 2019 6:54 pm
by jan
@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.