How to use JSON.NET in WooCommerce.NET - XiaoFaye/WooCommerce.NET GitHub Wiki
- Make sure you get WooCommerce.NET version 0.7.1 or higher from NuGet.org.
- Add Json.NET reference to your project.
- Define your own RESTAPI class as below:
public class MyRestAPI : RestAPI
{
public MyRestAPI(string url, string key, string secret, bool authorizedHeader = true,
Func<string, string> jsonSerializeFilter = null,
Func<string, string> jsonDeserializeFilter = null,
Action<HttpWebRequest> requestFilter = null) : base(url, key, secret, authorizedHeader, jsonSerializeFilter, jsonDeserializeFilter, requestFilter)
{
}
public override T DeserializeJSon<T>(string jsonString)
{
return JsonConvert.DeserializeObject<T>(jsonString);
}
public override string SerializeJSon<T>(T t)
{
return JsonConvert.SerializeObject(t);
}
}
- Now use your RESTAPI class to make Restful calls
using WooCommerceNET.WooCommerce.v2;
using WooCommerceNET.WooCommerce.v2.Extension;
MyRestAPI rest = new MyRestAPI("http://www.yourstore.co.nz/wp-json/wc/v2/", "<WooCommerce Key>", "<WooCommerce Secret");
WCObject wc = new WCObject(rest);
//Get all products
var products = await wc.Product.GetAll();