0

I have created a multidimenssional array.. which stores multiple rows from my database table..

 SqlDataAdapter da = new SqlDataAdapter("select  * from question_bank_details  where question_num  in (select top 2 question_num  from question_bank_details order by newid())", con5);
 DataTable data_table = new DataTable();
 DataList data_list = new DataList();
 da.Fill(data_table);

 string[,] array_questions = new string[dt.Rows.Count,dt.Columns.Count];

 for (int i = 0; i <dt.Rows.Count; i++)
 {
      for (int j = 0; j < dt.Columns.Count; j++)
      {
           array_questions[i, j] = dt.Rows[i][j].ToString();

      }
 }
 data_list.DataSource = data_table;
 data_list.DataBind();

now I need to convert this multi dimenssional array into JSON format.please help

4 Answers 4

4

You can use Json.NET 4.0, It is also available in Nuget

string output = JsonConvert.SerializeObject(array_questions);
Sign up to request clarification or add additional context in comments.

1 Comment

I just used JSON.NET for dotnet 4.0 for my project, and I can say it worked -perfectly- I suggest this answer.
0

Use this

JavaScriptSerializer js = new JavaScriptSerializer();
string json = js.Serialize(array_questions);

Source :How do I convert a c# two-dimensional array to a JSON object?

1 Comment

thankyou..but when sending the data, it is received as a very long single line ..how can i transfer it row wise?
0

this example is basically converting javascript to json....hope you might get some idea from this you need to use an open-source json parser and stringfier check at http://www.json.org/

https://github.com/douglascrockford/JSON-js/blob/master/json2.js after then you have to include the code and use the JSON.stringify() method on your array.

Comments

0
var serializer = new JavaScriptSerializer();
serializer.Serialize(array_questions); // This will serialize array to JSON string.

If you want to deserialize from JScript, use

JSON.Parse(array_questions);

Please refer this one also for JScript deserilazation How to return a HashTable from a WebService?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.