Hi All,
The result set return by the datastore is a JSON format which is different when compared with the JSON string returned by the datastore.ExportPlainJson built in method: teh column names are surrounded by the back slash character \
Example is shown below (both display only part of the JSON returned):
datastore result set returned in JSON
{"memHistoryLoad":[{"Compute_0001":1.0,"Policy_Type_Policy_Type_Name":"Member Reservation Points",
"Contract_Resort_Id":"142510000000004867","Contract_Resort_Name":"Divi Club"
String datastore.ExportPlainJson: the columns are surrounded by \ (back slash) character:
{"MemberHistory":["[{\"Compute_0001\":1.0,\"Policy_Type_Policy_Type_Name\":\"Member Reservation Points\",
\"Contract_Resort_Id\":\"142510000000004867\",\"Contract_Resort_Name\":\"Divi Club\"
Is there any other built-in method to extract the JSON string from the datastore?
Thank you,
Paulo Gomes
Interval International LLC
pgomes@intervalintl.com
Escape characters are a standard in JSON strings.
I don't know how to parse it in your front-end, but you can get the string very easily in PB:
// Parse
JSONParser lnv_JsonParser
Long ll_RootObject,ll_number_item, ll_number,ll_resultset_value_array, ll_object_item
String ls_ds_json
lnv_JsonParser = Create JSONParser
lnv_JsonParser.LoadString(ls_json)
ll_RootObject = lnv_JsonParser.GetRootItem()
// Get array
ll_resultset_value_array = lnv_JsonParser.GetItemArray(ll_RootObject, "resultset_value")
// Get the first item
ll_object_item = lnv_JsonParser.GetChildItem(ll_resultset_value_array, 1)
lnv_JsonParser.getitemtype(ll_object_item)
// Get a string of Plain JSON
ls_ds_json= lnv_jsonparser.getitemstring(ll_object_item)
Messagebox("Plain JSON", ls_ds_json)
Regards,
Logan
Thank you for the comment. Yes, it is very easy to parse the JSON string in PB.
The escape characters in the JSON string surprised me because the rows returned in JSON from the Primary Buffer of the Data Store object does not have escape characters.
Besides the fact that I have programmed/designed myself a number of C# REST web services along the past years with different .Net Frameworks and Visual Studio versions and none has escape characters built in.
However I already consumed some third-party REST web services that return JSON with escape characters.
So, you are right, in some situations, escape characters are embedded in JSON strings.
The good news is that it seems that our Java JSON parser is able to parse the escape characters. It is not a "final" word about it but it seems good so far.
I'll let you know by the end of the day and if it is confirmed that we can parse the strings with escape characters, we will be able to close this request.
Thank you for your time researching this.
Regards,
Paulo Gomes
pgomes@intervalintl.com
Good news: yes, the Java parser can parse the several different JSON result sets we generated so far from the REST Web API, in PB2019 and PB2019 R2 beta too.
This means that we can proceed and have this request Resolved.
Thank you.
Regards,
Paulo Gomes
pgomes@intervalintl.com