[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Creating a JSON array on the server

How do I create a JSON array on the server that can later be consumed on the client via JavaScript?
0
Ray Turner
Asked:
Ray Turner
1 Solution
 
Ivo StoykovCommented:
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
0
 
käµfm³d 👽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

0
 
Alexandre SimõesManager / Technology SpecialistCommented:
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!
0
 
Ray TurnerSenior ConsultantAuthor Commented:
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now