我有以下json代碼,有任何庫和方法,我使用mydatatable值轉換成json,因爲我發佈數據json格式。很難添加這些類型的參數。如何將數據轉換成json
using (var content = new StringContent("{ \"vehicles\": [ { \"vehicle_type\": \""+ vehicale_type +"\", \"vehicle_id\": \"" +vehicle_id+"\"," +
"\"vehicle_plate\": \"" +vehicle_plate+ "\", \"latitude\": "+latitude +"+, \"longitude\": "+longitude+", \"eta_minutes\": null, " +
"\"make\": \"null\", \"model\": \""+carModel+"\", \"color\": \"Black\", \"status\": \""+status+"\", " +
"\"driver_id\": \"" + driver_id + "\", \"driver_phone\": \"" + driver_phone + "\", \"driver_first_name\": \"" + driver_first_name + "\", " +
"\"driver_last_name\": \"" + driver_last_name + "\", \"direction\": { \"kph\": 20, \"heading\": 90 } }, " +
"{ \"vehicle_type\": \"" + vehicale_type2 + "\", \"vehicle_id\": \""+vehicle_id2+"\", \"vehicle_plate\": \""+vehicle_plate2+"\", \"latitude\":"+latitude2+", " +
"\"longitude\":" + longitude2 + ", \"eta_minutes\": null, \"make\": \"null\", \"model\": \"" + carModel2+ "\", " +
"\"color\": \"Black\", \"status\": \""+status2+"\", \"driver_id\": \""+driver_id2+"\", \"driver_phone\": \""+driver_phone2+"\", " +
"\"driver_first_name\": \"" + driver_first_name2+ "\", \"driver_last_name\": \"" + driver_last_name2 + "\", \"direction\": { \"kph\": 20, " +
"\"heading\": 90 } } ]}", System.Text.Encoding.Default, "application/json"))
{
using (var response = await httpClient.PostAsync("{supplier_id}/availability?version=2", content))
{
string responseData = await response.Content.ReadAsStringAsync();
}
}
你可能需要邏輯來轉換你的數據表中的對象數組,然後你可以轉換成json字符串 –