Hi Rick,
I am a little stuck. I can retrieve an individual customer via my REST API. However, I'm having an issue trying to update that customer. https://webconnection.west-wind.com/docs/Walk-Through-Tutorials/Step-by-Step-Creating-a-JSON-REST-Service/Step-6-Using-FoxPro-to-access-the-JSON-HTTP-API.html
Here is the step I am on:
lcCustomerId = "_4FG12Y7UD"
loHttp = CREATEOBJECT("wwHttp")
*** Returns JSON array
lcJson = loHttp.HttpGet(lcBaseUrl + "customer.csvc?id=" + lcCustomerId)
*** Deserialize customer list into a collection
loSer = CREATEOBJECT("wwJsonSerializer")
loCust = loSer.DeserializeJson(lcJson)
? loCust.LastName
? loCust.FirstName
? loCust.COmpany
? loCust.Address
? loCust.Email
? loCust.Entered
? loCust.Updated
The loCust object is created, but the only way I can access it is via:
FOR EACH loCustomer IN loCust
lcLast_Name = ALLTRIM(loCustomer.Last_Name)
ENDFOR
I cannot access this object via ?loCust.Last_Name
It's like my Json returned has one too many levels or something and I have to use the FOR EACH approach. Any idea why? Thought I would ask before going too far down an incorrect path.
Thanks,
Steve
Looks like your result is an array not a single object. If you returned a cursor - even if it's a single record - it'll be an array of objects hence you have to iterate over the data.
If you want to return a single object from the server, you have to return an object and you have to convert the first record to an object. You can do that via SCATTER NAME loObject MEMO and then return the resulting object.
FWIW, you should probably use a REST client like West Wind WebSurge or Postman to test your APIs so you can easily see what the server is returning and have an easy, quick and repeatable way to test your API endpoints. Using that tool you'll easily see the array vs. object result and it's really useful when you come back to your project after some time and you have to remember what each endpoint is supposed to do - it serves as a sort of documentation.
+++ Rick ---