'How to get values from a list while calling API
i am trying to call an API, to insert some values innit,but first i need to take the values from a list.My problem is in line 10, and i can't fix it. The error is:
cannot convert from 'IC.xxx.logic.Data' to 'Newtonsoft.Json.Linq.JToken?'
Below is the code:
public static void InsertRecords(List<Data> selectedData)
{
var access_token = xxxToken();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.example.com/xx/v2/xxx");
request.Method = "POST";
request.Headers["Authorization"] = "xxx " + access_token;
JObject requestBody = new JObject();
JArray recordArray = new JArray();
JObject recordObject = new JObject();
10)recordObject.Add("CUSTOMER_COMPANY_NAME", selectedData[0]);
recordObject.Add("Customer_Number", selectedData[2]);
recordObject.Add("Comapny_Street_1", selectedData[10]);
}
Thank you for your time!
Solution 1:[1]
Would suggest creating an object instance and then cast to JObject for ease. (Convert from an object/list to JObject/JArray)
dynamic input = new
{
CUSTOMER_COMPANY_NAME = selectedData[0],
Customer_Number = selectedData[2],
Comapny_Street_1 = selectedData[10]
};
JObject recordObject = JObject.FromObject(input);
Otherwise, you should provide the JSON in a string to solve the error above.
recordObject.Add("CUSTOMER_COMPANY_NAME", JObject.Parse(selectedData[0]));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yong Shun |
