如何为json制作序列化程序? [英] How do I make a serializer for json?

查看:82
本文介绍了如何为json制作序列化程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我正在构建一个asp.net web api并用ember调用它,虽然我已经用postman测试了api(用于测试HTTP请求的chrome扩展)并且它正在工作,当我尝试用它调用它时它没有工作......看了一会儿后我看到几个人在谈论序列化器......我必须使用一个吗?如果是这样的话?

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 ?

推荐答案

抱歉,我必须使用吗?与为JSON制作一个序列化器一样多废话。第一个问题的答案是:你决定要用什么。至于序列化: JSON本身就是一个序列化器。请参阅:

https://developer.mozilla .org / zh-CN / docs / Web / JavaScript / Reference / Global_Objects / JSON [ ^ ],

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_native_JSON [ ^ ],

序列化: https://developer.mozilla.org/en-US/docs/Web/JavaScript / Reference / Global_Objects / JSON / stringify [ ^ ],

反序列化: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse [ ^ ]。



对于服务器端的JSON序列化和反序列化,这已经为您完成了:

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 [ ^ ]。



另见我过去的答案:

如何将对象类型转换为C#类对象类型 [ ^ ],

如何将多级json数据转换为C#对象? [ ^ ]。



如您所见,您可以解释数据(非数据转换)在.NET代码中在客户端创建的。这种方法可以基于此: https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer%28v=vs.110%29.aspx [ ^ ](我已经在上面提到的答案中解释过了。



关于你的......当我试着用它来调用它时它不起作用有点问题,抱歉,如果您没有提供任何相关信息,任何人都无法帮助您。由于目前的暴风雪,我对你硬盘的访问有限......



-SA
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


这篇关于如何为json制作序列化程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆