Hi I’d like to build a simple json looking like this: {"Count" : "55", "total" : "125,55"}
On my vb method i’m doing this to encode it:
Dim json As String = "{""Count"" : "" " & intCount & " "", ""total"" : "" " & intTotal & " "" }"
But I think Im missing something to escape the quotes, when my browser received it, it looks like this: {"d":"{\"Count\" : \" 5 \", \"total\" : \" 55 \" }"}
making it unreadable for jQuery…
any idea how to encode this json in a simple way?
If you want to keep it simple, you would bypass all the syntax nuances all together (its error-prone) and add some flexibility to your app by allowing the framework to serialize (or deserialize) your data for you.
In a nutshell, you would create an object with those properties (count, total,…future additions?) and use the
DataContractJsonSerializerwhich can be found in theSystem.Runtime.Serialization.Jsonnamespace.Here’s a tutorial: How to: Serialize and Deserialize JSON Data
MSDN: DataContractJsonSerializer Class