Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

SRP_JsonX_Get

I am trying to get this example working as I want to get all values from an array (like employees) but even the examples is not working , it is returning an error.
Using the following as an example, can you get all the lastname(s) in one call like - SRP_JsonX_Get('employees.lastname') or do you have to loop thru based on the count.

ERROR: Invalid value., Line 1, Pos 334


$insert SRPJSONX Json = '{' Json := ' "employees": [' Json := ' {' Json := ' "firstname": "John",' Json := ' "lastname": "Doe",' Json := ' "age": 21' Json := ' },' Json := ' {' Json := ' "firstname": "Anna",' Json := ' "lastname": "Smith",' Json := ' "age": 32' Json := ' },' Json := ' {' Json := ' "firstname": "Peter",' Json := ' "lastname": "Jones",' Json := ' "age": 43' Json := ' },' Json := ' ],' Json := ' "nums": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]' Json := ' "active": true,' Json := ' "alwaysnull": null,' Json := ' "alwaysstring": "4.321"' Json := '}' Success = SRP_JsonX_Parse('MyDocument', Json) If Success EQ 0 then Error = SRP_JsonX_Error() end else Value = SRP_JsonX_Get('employees[2].lastname') end SRP_JsonX_End()

Comments

  • Barry - Our apologies. The code that generates the JSON had a couple of typos in it. I've corrected it and now the entire code snippet works. Let us know if you still have questions.
  • To answer your question, you need to loop through the array and get the values one at a time.
  • Great, thanks.
    SRP_JsonX is the best thing since sliced bread (and http_frameworks) - best web combination!!!!
Sign In or Register to comment.