If I have in my db a table called User with name, Id, age fields and I want to get these data and put it in a var as a JSON serialize, then I want to send it to javascript page to reform it as I want . I need to know how to put these data in a var as a JSON, how to read the data in the javascript file (how to deal with each one. for example : array[name]) !!!?
which thing is more better to deal with these data in asp.net code then send it in the javascript or to send it to the javascript and then to deal with !!? thank u 😀
If I have in my db a table called User with name, Id, age
Share
If you have an object in .NET you can serialize it using the
JavaScriptSerializerThis way you won’t have to worry about escaping quotes or anything. Now that you have a string, you can feed that to your javascript:
The other way around, you may have a javascript object, that you want to pass to the server:
If you pass the string
userJsonto the server, you can then deserialize it. If you know that the JS object corresponds entirely, in terms of property names, to a .NET object, or an array of .NET objects, say, you can deserialize it as such:If there isn’t a .NET object that can be directly mapped to the structure of the JS object, you’ll have to use