Привет, я хотел бы выяснить, как после сериализации объекта как сопоставить поля в модели POST API?
Кажется, я не могу понять это, см. Код ниже, я решил Сериализация и может показать результаты моего SQL запроса в консоли, но как вы сопоставите их с полями, которые должны быть заполнены в API?
using (SqlCommand command = new SqlCommand(query, connection))
{
connection.Open();
List<ProductSQL> myObjectList = new List<ProductSQL>();
var reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
ProductSQL myObject = new ProductSQL();
myObject.sku = reader["sku"].ToString();
myObject.description = reader["description"].ToString();
myObjectList.Add(myObject);
}
}
var JsonResult = JsonConvert.SerializeObject(myObjectList);
Console.WriteLine(JsonResult);
}
/* Program Initialization Now need to map the products to their respective fields from the SQL Database to the API*/
Console.WriteLine("Post Articles To API");
HttpResponseMessage response2;
Product NewProduct = new Product();
NewProduct.sku = <What to do here , I would like to map this to the serialized JSON> ;
NewProduct.title = ;
NewProduct.description =;
Продукт SQL .cs
public class ProductSQL {
public string sku { get; set; }
public string title { get; set; }
public string description { get; set; } }
}