0

In PHP I can do this for example:

while($r = mssql_fetch_assoc($sth)) {
   $rowsField["rowsinfo"][] = $r;
}

print json_encode($rowsField);

Which basically returns a (two/multi dimensional I believe) array and returns it in a JSON format.

I am trying to achieve the same thing as I am moving my website to .NET.

So I am trying to do this in a WCF Web Service and so far I have only had success getting this far with Newtonsoft JSON Converter.

I managed to return a DataTable in JSON format but I now need it to return almost like the array like: [["rowsinfo"]{"Address":"15 Tyne Cresent","Name":"John Smith"}] etc...

How can this be achieved? Is it a DataTable I need to return still?

Thanks

2 Answers 2

0

Perhaps you'd find this interesting: C# WCF REST client JSON array or Generate JSON array with WCF

Looks like there are a lot of questions about it already where you could potentially find more information.

Sign up to request clarification or add additional context in comments.

Comments

0

return this List<string, List<string>()>()

or just the multidimensional array

string[,] array = new string[4, 2];

3 Comments

Will this work if I don't know what columns I will be displaying from the database? Basically, the SQL Query that is executed is dynamic so will not always return the same data
Hmm yes, it that is the case, I just edited my answer
hmm, it doesn't seem to like this. How would I then add my SQL results to this list? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.