Creating a JSON array on the server

Ray Turner
Ray Turner used Ask the Experts™
on
How do I create a JSON array on the server that can later be consumed on the client via JavaScript?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,
The obvious way is to concatenate a string like "{" + mykey + ":" + myval + "}"
and to send this result string to the client.

Each language has its own implementation to parse and stringify from and to JSON. If you specify server language, you might be directed to concrete implementation.

HTH
Ivo Stoykov
Most Valuable Expert 2011
Top Expert 2015

Commented:
Just create a regular array, and then use one of the JSON serializers (e.g. JSON.NET) to convert the array into JSON.

e.g.

Imports Newtonsoft

...

Dim theArray() As String
Dim jsonString As String = JsonConvert.SerializeObject(theArray)

Open in new window

Manager / Solutions Architect
Commented:
Chances are you don't need JSON.NET, it occurred to me often that the .net built-in serializer was more than enough.
have a look here: http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

Some years ago I wrote this article regarding deserialization but the main concept is the same:
http://www.codeproject.com/Tips/210810/Deserialize-JSON-with-Csharp

Cheers!
Ray TurnerSenior Consultant

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial