West Wind Internet and Client Tools
JsonDeserialize issue
Gravatar is a globally recognized avatar based on your email address. JsonDeserialize issue
  ddprlewis
  All
  Jun 5, 2019 @ 02:06pm

I have an issue with the deserializer appearing to not work correctly. I am getting back the attached json and when I go do deserialize it, I get the count, but no collection of the records in the json. This is coming from paylocity if that matters.

Simple code to test:

DO wwHttp
DO wwJsonSerializer
loSer = CREATEOBJECT("wwJsonSerializer")
lcJson = filetostr("json test.json")
o = loSer.DeserializeJson(lcJson)

Here's the json that you can save:

[{"employeeId":"7580","statusCode":"A","statusTypeCode":"A"},{"employeeId":"8878","statusCode":"T","statusTypeCode":"T"},{"employeeId":"9828","statusCode":"T","statusTypeCode":"T"}]

Here is the results I am getting:

Any ideas on settings or something I can use to get it to work. As a side note, when I get an employee information (single record), it does properly populate each field as an property on the returned object, so I think it is working properly and figure it is just something I am missing and not seeing in the documentation.

Any help is much appreciated.

Gravatar is a globally recognized avatar based on your email address. re: JsonDeserialize issue
  Rick Strahl
  ddprlewis
  Jun 5, 2019 @ 05:47pm

Looks to me like you're getting a collection. What are you doing to read the data from the collection?

This works fine for me:

CLEAR
DO wwJsonSerializer

TEXT TO lcJson NOSHOW
[
    {
        "employeeId": "7580",
        "statusCode": "A",
        "statusTypeCode": "A"
    },
    {
        "employeeId": "8878",
        "statusCode": "T",
        "statusTypeCode": "T"
    },
    {
        "employeeId": "9828",
        "statusCode": "T",
        "statusTypeCode": "T"
    },
    {
        "employeeId": "8877",
        "statusCode": "T",
        "statusTypeCode": "T"
    },   
    ...
]
ENDTEXT

loSer = CREATEOBJECT("wwJsonSerializer")
loObj = loSer.DeserializeJson(lcJson)

? loObj.Count

FOR EACH loItem IN loObj  FOXOBJECT
   ? loItem.EmployeeId + " " + loItem.StatusCode
ENDFOR


*FOR lnX = 1 TO loObj.Count
*   loItem = loObj.Item(lnX)
*   ? loItem.EmployeeId + " " + loItem.StatusCode
*ENDFOR

Don't look at the debugger for collections because the Fox debugger won't drill into them. You have to look at individual items (ie. o[1]).

Tip: Format your Json

JSON Tip when posting here: Open a JSON formatted string in VS Code, then highlight all the text and format with Ctrl-A and Ctrl-K-F to format the JSON nicely and make it easier for pasting and displaying here.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: JsonDeserialize issue
  ddprlewis
  Rick Strahl
  Jun 6, 2019 @ 06:55pm

Rick,

That was exactly it. For some reason I thought you could see collections in the debuger and at minimum that they showed up as objects. It was throwing me when I saw it as a character field.

Thanks for your continued support of these great tools.

© 1996-2019