West Wind Internet and Client Tools
Deserialize JSON from Shopify ?
Gravatar is a globally recognized avatar based on your email address. Deserialize JSON from Shopify ?
  Steve
  All
  Jun 3, 2022 @ 12:20pm

Hi All,
I am trying to work with (learn) the Shopify API. So far it's going ok. I am querying a product and do get a JSON response. I am now trying to deserialize the JSON response per Rick's REST API document from VFP Fest 2021. The deserialization doesn't seem to be working and I'm wondering what's going on, and/or if the wwJsonSerializer utility will handle the response from Shopify?

Here is the response when I query Id, Title, and Vendor from the Products file: {"products":[{"id":7047734788132,"title":"ZH-GPEE-3BDB-2FLX - Integrated Hydrostatic Transaxle","vendor":"HG"}]}

I pass the above to wwJsonSerializer via: loProd = loSer.Deserialize(lcJson)

However, ? loProd.id, ? loProd.title, and ? loProd.vendor error with Property not found. So, it seems the deserialization is not working.

Does the above Json look like it should be handled by wwJsonSerializer? Looking at the code, there seems to be some limitations on what can be deserialized. Do I need to massage the Json before passing it to wwJsonSerializer?

TIA,
Steve

Gravatar is a globally recognized avatar based on your email address. re: Deserialize JSON from Shopify ?
  Rick Strahl
  Steve
  Jun 3, 2022 @ 02:21pm

You're getting back an object with a property that's an array in JSON, which will translate into a collection in the deserialized object:

loResponse = loSer.Deserialize(lcJson)

FOR loProduct in loResponse.Products FOXOBJECT
    ? loProduct.Id + " " + loProduct.Title
ENDFOR

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Deserialize JSON from Shopify ?
  Steve
  Rick Strahl
  Jun 4, 2022 @ 08:29am

Thanks Rick!! You da man!!

© 1996-2024