Hi,
While integrating with other environments the most common mode of data export is in the form of JSON string. In this post we will see how to construct JSON string from customer data.
Note: CG_BuildJSON is a runnable class.
class CG_BuildJSON
{
/// <summary>
/// Construct JSON String.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
System.IO.StringWriter stringWriter;
Newtonsoft.Json.JsonTextWriter jsonWriter;
CustTable custTable;
stringWriter = new System.IO.StringWriter();
jsonWriter = new Newtonsoft.Json.JsonTextWriter(stringWriter);
select AccountNum, BankAccount, Party
from custTable
where custTable.AccountNum == "1000";
str sJSON = "";
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("AccountNum");
jsonWriter.WriteValue(custTable.AccountNum);
jsonWriter.WritePropertyName("Name");
jsonWriter.WriteValue(custTable.nameAlias());
jsonWriter.WritePropertyName("BankAccount");
jsonWriter.WriteValue(custTable.BankAccount);
jsonWriter.WriteEndObject();
sJSON = stringWriter.ToString();
Info(strFmt("%1", stringWriter.ToString()));
}
}
Regards,
Chaitanya Golla
*This post is locked for comments