I want to convert the JSON output of the Shopify API call into an object I can manipulate in C#.
This is the code I have so far
1 var client = new ShopifyAPIClient(new ShopifyAuthorizationState { AccessToken = token, ShopName = shopName });
2 var orders = JsonConvert.DeserializeObject((string)client.Get("/admin/orders.json"));
3
4 foreach(object order in orderss){
5 // do stuff with member variables of object
6 }
Error on line 4: Type 'object' is not enumerable
this page has the format of the JSON object returned.
this page has an example of how to deserialize JSON into a C# object that a class defined 定义类的C#对象的示例
Is there any way to deserialize the JSON into a C# object that can be enumerable without defining a class? If not, are the Shopify classes defined somewhere where I can copy them into my project?
Thank you in advance!
it has another orders
object under root object. Try
dynamic dynObj = JsonConvert.DeserializeObject(json);
foreach (var order in dynObj.orders)
{
Console.WriteLine("{0} {1}",
(string)order.email,
(string)order.payment_details.credit_card_number);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.