Problems with XPRIM_RandomAccessJsonReader
Posted: Wed May 07, 2025 2:23 am
I am trying to retrieve values from a returned JSON using XPRIM_RandomAccessJsonReader.
I am very new to this and have been using the web page as a reference https://docs.lansa.com/14/en/lansa018/c ... 1_0085.htm
The JSON I receive is:
I need to retrieve the value assigned to id 8 (60484 in this example).
The code I have created (using example from the above web page) is :
The value for field #xIDN is not being set.
Any help to get this working will be greatly appreciated.
I am very new to this and have been using the web page as a reference https://docs.lansa.com/14/en/lansa018/c ... 1_0085.htm
The JSON I receive is:
Code: Select all
{
"name":"X0010GetNextNumber",
"template":"D0000065",
"submitted":true,
"result":
{
"output":
[
{"id":1,"value":"01"},
{"id":2,"value":1},
{"id":3,"value":""},
{"id":4,"value":""},
{"id":5,"value":0},
{"id":6,"value":0},
{"id":7,"value":""},
{"id":8,"value":60484}
]
}
}The code I have created (using example from the above web page) is :
Code: Select all
#Reader.SetSourceHttpResponse HTTPRESPONSE(#Request.Response) ERRORINFO(#ErrorInfo)
IF (#ErrorInfo.OK.IsFalse)
RETURN
ENDIF
BEGIN_LOOP USING(#JCount) TO(8)
USE BUILTIN(numeric_string) WITH_ARGS(#JCount) TO_GET(#@Ch)
CHANGE FIELD(#JSONPath) TO('''result/output/''')
SUBSTRING FIELD(#@Ch 1 1) INTO_FIELD(#JSONPath 15 1)
#Reader.BeginObjectWithPath( #JSONPath )
#xIDn := #Reader.ReadnumberWithPath( '''id''' )
IF (#xIDn = 8)
#xjsonch := #Reader.ReadStringWithPath( '''value''' ).asNativeString
#Reader.EndObject
LEAVE
ENDIF
#Reader.EndObject
END_LOOPAny help to get this working will be greatly appreciated.