Hi dgunners,
You need to use FromObject method of JArray class.
Please refer below sample.
HTML
<asp:Label ID="lblMessage" runat="server" />
Namespace
C#
using Newtonsoft.Json.Linq;
VB.Net
Imports Newtonsoft.Json.Linq
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
JObject jbody = new JObject();
JObject lineItems = new JObject();
lineItems.Add("beneficiaryName", JArray.FromObject(new[] { "Receiver 1", "Receiver2" }));
lineItems.Add("beneficiaryAccount", JArray.FromObject(new[] { "0111222333", "0444555666" }));
lineItems.Add("bankCode", JArray.FromObject(new[] { "011", "04" }));
lineItems.Add("beneficiaryAmount", JArray.FromObject(new[] { "10", "50" }));
lineItems.Add("deductFeeFrom", JArray.FromObject(new[] { "1", "0" }));
jbody.Add("lineItems", lineItems);
lblMessage.Text = Newtonsoft.Json.JsonConvert.SerializeObject(jbody);
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim jbody As JObject = New JObject()
Dim lineItems As JObject = New JObject()
lineItems.Add("beneficiaryName", JArray.FromObject({"Receiver 1", "Receiver2"}))
lineItems.Add("beneficiaryAccount", JArray.FromObject({"0111222333", "0444555666"}))
lineItems.Add("bankCode", JArray.FromObject({"011", "04"}))
lineItems.Add("beneficiaryAmount", JArray.FromObject({"10", "50"}))
lineItems.Add("deductFeeFrom", JArray.FromObject({"1", "0"}))
jbody.Add("lineItems", lineItems)
lblMessage.Text = Newtonsoft.Json.JsonConvert.SerializeObject(jbody)
End If
End Sub
Screenshot