Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert an object into json using newtonsoft but not get the out in required fdormat
    primarykey
    data
    text
    <p>I created two classes </p> <p><em><strong>BingMapsProduct.cs</em></strong></p> <pre><code>public BingMapsProduct() { productId = int.MinValue; productName = string.Empty; productPrice = double.MinValue; contractorStatus = string.Empty; } public int productId; public string productName; public double productPrice; public string contractorStatus; </code></pre> <p><em><strong>Contactor.cs</em></strong></p> <pre><code>public BingMapsContractor() { contactSystemType = string.Empty; agreementType = string.Empty; totalCount = int.MinValue; productList = new List&lt;BingMapsProduct&gt;(); } Public string contactSystemType; Public string agreementType; Public int totalCount; public List&lt;BingMapsProduct&gt; productList; </code></pre> <p>Code of Class that i use for conversion</p> <pre><code> DataSet objDataSet = GetContractorByCategory(jobId); \\returns the data from database List&lt;BingMapsContractor&gt; contractorList = new List&lt;BingMapsContractor&gt;(); foreach (DataRow contractorDR in objDataSet.Tables[0].Rows) { BingMapsContractor contractor = new BingMapsContractor(); contractor.ContactSystemType =(string)contractorDR["Contact_System"]; contractor.AgreementType =(string)contractorDR["agreementType"]; contractor.TotalCount = (int)contractorDR["totalCount"]; foreach (DataRow ProductDR in objDataSet.Tables[1].Select("contractorid = " + contractor.ContractorId)) { BingMapsProduct product = new BingMapsProduct(); product.ProductId = (int)ProductDR["productId"]; product.ProductName = Convert.ToString(ProductDR["CategoryName"]); product.ProductPrice = Convert.ToDouble(ProductDR["productPrice"]); product.ContractorStatus = Convert.ToString(ProductDR["contractorStatus"]); contractor.productList.Add(product); } contractorList.Add(contractor); } // Return JSON data string strJson = JsonConvert.SerializeObject(contractorList,Formatting.Indented); return strJson; } </code></pre> <p><em><strong>Output</em></strong></p> <pre><code>"productList": [ { "ProductId": 16081, "ProductName": "Appliance Dishwasher RE/RE + Haulaway - HOME DEPOT", "ProductPrice": 95.0, "ContractorStatus": "Provider" } ], "ContactSystemType": "System", "AgreementType": "QC", "TotalCount": 0 </code></pre> <p>But i want the product list array in end.</p> <pre><code>"AgreementType": "QC", "TotalCount": 0, "productList": [ { "ProductId": 16081, "ProductName": "Appliance Dishwasher RE/RE + Haulaway - HOME DEPOT", "ProductPrice": 95.0, "ContractorStatus": "Provider" } ] </code></pre> <p>Because i have to pass above json to bing maps api which reuire a formated json</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload