Code: Select all
Define_Com Class(#XPRIM_JsonReader) Name(#JSONReader) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_ErrorInfo) Name(#ErrorObject)
Define_Com Class(#XPRIM_JsonObject) Name(#JsonObj) Reference(*DYNAMIC)
Define_Com Class(#XPRIM_File) Name(#JsonFile)
Define_Com Class(#PRIM_BOLN) Name(#wk_found)
Define Field(#ErrMsg) Type(*CHAR) Length(200)
#ErrMsg := *Blank
#JsonFile := #STD_QSEL.Trim
#JSONReader <= *New #XPRIM_JsonReader
#JSONReader.SetSourceFile Path(#JsonFile.path) Errorinfo(#ErrorObject)
* if the json is not properly formed
If (*Not #errorobject.OK)
#ErrMsg := #ErrorObject.ErrorMessage.AsNativeString
Message Msgtxt(#ErrMsg)
Return
Endif
* start processing the file
#JSONReader.ReadBeginArray Found(#wk_found)
* check if orders were returned
If (#wk_found)
* loop over all orders
#JSONReader.MoveNext Ok(#wk_found)
Dowhile (#wk_found *And (*Not #JSONReader.IsEndArray))
#JSONReader.ReadObject Found(#wk_found) Result(#JsonObj)
#JSONReader.MoveNext Ok(#wk_found)
*** Parse the data from JsonObj here ****
Endwhile
Endif
I have a work around that worked. I leave the CCSID to 819. FTP the file to my local PC as ASCII, then ftp back to the iSeries folder which is now CCSID 819. It worked and I didnt encounter any error. Since this work around won't work for a client, my question is, how will you read a JSON file with CCSID 37? Or how can I convert the file so that Json Reader can read it?
This is what the file looks like with CCSID 37. #XPRIM_JsonReader cannot read it.

When you convert it to CCSIS 819 (using CHGATR command), this what it looks like. You'll see the first character is translated.
