Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey guys, I'm building an asp.net web api and calling it with ember, although I've tested the api with postman(chrome extension for testing HTTP requests) and it's working, when I try to call it with ember it's not working... After looking around for a while I saw a few guys talking about serializers... do I have to use one? if so how ?
Posted
Comments
Mehdi Gholam 9-Feb-15 12:53pm    
The general answer is with a lot of hard work, but luckily you can build on existing libraries.
Sergey Alexandrovich Kryukov 9-Feb-15 13:46pm    
What libraries you are talking about? Please see my answer.
—SA
[no name] 9-Feb-15 23:58pm    
You can use a serializerable object to hold your data and you can easily make the data serializable using those kind of objects.

For example a DATASET is a serializable object. You can keep your table value in the dataset and easily you can convert the data into JSON format using the serializable class estentions.

This example will help you get a quick understanding on how the serilizable objects work and how you can use it.

1 solution

Sorry, but "do I have to use one?" is as much of nonsense as "make a serializer for JSON". The answer to the first question would be: "you decide what you want to use". As to the serialize: JSON is itself a serializer. Please see:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON[^],
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_native_JSON[^],
serialization: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify[^],
deserialization: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse[^].

As to JSON serialization and deserialization on the server side, this is already done for you:
https://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See also my past answers:
How To Convert object type to C# class object type[^],
how to conver multi level json data to C# Object?[^].

As you can see, you can interpret data (non-data contract) created on client side in .NET code. This approach can be based on this: https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer%28v=vs.110%29.aspx[^] (I already explained how in my answers referenced above).

As to your "…when I try to call it with ember it's not working" kind of questions, sorry, anyone hardly can help you if you are not providing any relevant information. Due to the current snow storm, my access to your hard drive is somewhat limited…

—SA
 
Share this answer
 
Comments
Mehdi Gholam 10-Feb-15 0:50am    
Sorry Sergey! but json is not a serializer it is merely the standard, there are json a multitude of serializers see : http://json.org/
Sergey Alexandrovich Kryukov 10-Feb-15 12:15pm    
It depends on the context. JSON is the word which denotes different notions. One of them is JavaScript native object JSON, and that object is the serializer. I hope I clarified. Also, it should be understood in the context of my post as related to the inquirer question.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900