Hi
In below code i am getting above error. Secondly i don't want to pass Hardcode values like 160060
C#
var body = "{" + Environment.NewLine +
$" \"origin\" : \"{160060}\"," + Environment.NewLine +
$" \"destination\" : \"{160062}\"," + Environment.NewLine +
$" \"payment_type\" : \"{prepaid}\"," + Environment.NewLine +
$" \"order_amount\" : \"{1000}\"" + Environment.NewLine +
"}";Thanks

Pasang TamangRank #449 · 5.6K reputationPosted Jan 8, 2023, 8:16 AM EST
Hi,
Since you are trying to create json string, I would suggest to use Newtonsoft.Json. You have to install Newtonsoft.Json package fro NuGet and use code like below
public class OrderItem { [JsonPropertyName("origin")] public int Origin { get; set; } [JsonPropertyName("destination")] public int Destination { get; set; } [JsonPropertyName("payment_type")] public string PaymentType { get; set; } [JsonPropertyName("order_amount")] public decimal OrderAmount { get; set; } }static void Main(string[] args) { var bodyObject = new OrderItem { Origin = 160060, Destination = 160062, PaymentType = "prepaid", OrderAmount = 1000 }; var body = JsonConvert.SerializeObject(bodyObject, Formatting.Indented); Console.WriteLine(body); Console.Read(); }Regards,
Pasang
Pasang TamangRank #449 · 5.6K reputationPosted Jan 8, 2023, 8:17 AM EST
As you said Prepaid does not exist, this must be any variable in your code. In the code that I suggested, you can put any value you want from your data source.
Regards,
Pasang