Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON Format - convert Dataset to JSON
    text
    copied!<p>I have C# WCF service.There I want to convert to JSON String.DataSet contain more table Currntly coming result some wrong json format.</p> <pre><code> { "Target1": [ { "BusinessUnit": "MASS", "RetailerCode": "TEST0002" }, { "BusinessUnit": "MASS", "RetailerCode": "TEST0008" } ] }{ "PDCheque1": [ { "BusinessUnit": "MASS", "AccountCode": "TEST0003" } ] } 0 { "OutStanding1": [ { "BusinessUnit": "MASS", "Year": "2010" }, { "BusinessUnit": "MASS", "Year": "2010" } ] </code></pre> <p>}</p> <p>Here is coverting method:</p> <pre><code> //Converting dataset to json public String ConverTableToJson(DataSet dsDownloadJson){ String tableData = ""; StringBuilder Sb = new StringBuilder(); Sb.Append("{\""); foreach (DataTable dt in dsDownloadJson.Tables) { DataTable dtDownloadJson = dt; string[] StrDc = new string[dtDownloadJson.Columns.Count]; string HeadStr = string.Empty; Sb.Append( dtDownloadJson.TableName + "1\" : ["); if (dtDownloadJson.Rows.Count &gt; 0) { for (int i = 0; i &lt; dtDownloadJson.Columns.Count; i++) { StrDc[i] = dtDownloadJson.Columns[i].Caption; HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\","; } if (HeadStr.Length &gt; 0) { HeadStr = HeadStr.Substring(0, HeadStr.Length - 1); for (int i = 0; i &lt; dtDownloadJson.Rows.Count; i++) { string TempStr = HeadStr; Sb.Append("{"); for (int j = 0; j &lt; dtDownloadJson.Columns.Count; j++) { TempStr = TempStr.Replace(dtDownloadJson.Columns[j] + j.ToString() + "¾", dtDownloadJson.Rows[i][j].ToString()); } Sb.Append(TempStr + "},"); } Sb = new StringBuilder(Sb.ToString().Substring(0, Sb.ToString().Length - 1)); } else { Sb.Append("0 }"); } } else { Sb.Append("0 }"); } Sb.Append("]}"); } return Sb.ToString(); ; } </code></pre> <p>IF the table doesn't contain records then it need to return "0" like `Tablename [{0}]'</p> <p>Its coming like this.Its wrong in 2nd set <code>PDCheque1</code> place.</p> <p>How I want to format?</p> <p>In Android I want to gt the each set using tablename i.e <code>PDCheque1</code> ,'Target1` like wise .</p> <p>1st set is ok to get the result.When I pass <code>JSONArray array = jsonobject.getJSONArray(tablename);' It say no</code> `PDCheque1`` </p> <p>Please help me...</p> <p>Thanks in advance</p>
 

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