Tag: json

Web服务应该返回json

我需要我的Web服务才能返回JSON … 我的.asmx文件中有以下代码: namespace Feed { [WebService(Namespace = “http://tempuri.org/”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [System.Web.Script.Services.ScriptService] public class searchPerson : System.Web.Services.WebService { [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public Person GetDave() { Person dave = new Person(); dave.FirstName = “Dave”; dave.LastName = “Ward”; return dave; } } } 返回以下内容: Dave Ward 如何强制它返回JSON而不是XML?

在Windows Mobile上有没有可以在C#中读取JSON的库?

我试图找到一个库来解析Windows Mobile上的C#上的JSON(使用Visual Studio 2005)。 我发现允许我在C#(litjson和Jayrock)中解析JSON的库在Windows Mobile上不起作用,它们需要.NET紧凑框架中不存在的类。 有没有我忽略过的图书馆? 或者在这种情况下还有另一种解析JSON的简单方法吗?

使用JavaScriptSerializer序列化词典

显然, IDictionary被序列化为KeyValuePair对象的数组(例如, [{Key:”foo”, Value:”bar”}, …] )。 是否可以将其序列化为对象(例如, {foo:”bar”} )?

使用Json.NET序列化为NDJSON

是否可以使用Json.NET序列化为NDJSON ( Newline Delimited JSON)? Elasticsearch API使用NDJSON进行批量操作,我发现没有任何迹象表明任何 .NET库都支持这种格式。 这个答案提供了反序列化NDJSON的指导,并且注意到可以独立地序列化每一行并加入换行符,但我不一定称之为支持 。

反序列化DataTable后,DateTime列类型变为String类型

我有一个DataTable有两列。 ShipmentDate(DateTime)和Count(Int)。 在我反序列化字符串后,我注意到如果第一个itemarray值为null,ShipmentDate的类型就变成了字符串。 请查看以下示例。 除第一个数组项外,json字符串都有相同的数据。 string jsonTable1 = “[{\”ShipmentDate\”:null,\”Count\”:3},{\”ShipmentDate\”:\”2015-05-13T00:00:00\”,\”Count\”:13},{\”ShipmentDate\”:\”2015-05-19T00:00:00\”,\”Count\”:1},{\”ShipmentDate\”:\”2015-05-26T00:00:00\”,\”Count\”:1},{\”ShipmentDate\”:\”2015-05-28T00:00:00\”,\”Count\”:2}]”; string jsonTable2 = “[{\”ShipmentDate\”:\”2015-05-13T00:00:00\”,\”Count\”:13},{\”ShipmentDate\”:null,\”Count\”:3},{\”ShipmentDate\”:\”2015-05-19T00:00:00\”,\”Count\”:1},{\”ShipmentDate\”:\”2015-05-26T00:00:00\”,\”Count\”:1},{\”ShipmentDate\”:\”2015-05-28T00:00:00\”,\”Count\”:2}]”; DataTable tbl1 = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonTable1); DataTable tbl2 = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonTable2); Console.WriteLine(tbl1.Columns[“ShipmentDate”].DataType); Console.WriteLine(tbl2.Columns[“ShipmentDate”].DataType); 在我的场景中,第一个项目数组的ShipmentDate可以为null,并通过将其转换为字符串类型来创建问题。 我有一种情况,数据表的模式是动态的。 我不能创建强类型的类。

无法将当前JSON数组(例如)反序列化为类型

我有这样的课; public class MyStok { public int STId { get; set; } public int SM { get; set; } public string CA { get; set; } public string Br { get; set; } public string BNo { get; set; } public decimal Vat { get; set; } public decimal Price { get; set; } } […]

实现PropertyChangedBase时的caliburn.micro序列化问题

我正在开发一个客户端/服务器数据驱动的应用程序,使用caliburn.micro作为前端,使用Asp.net WebApi 2作为后端。 public class Person { public int Id {get;set;} public string FirstName{get;set;} … } 该应用程序包含一个名为“Person”的类。 “Person”对象是序列化的(JSON),并使用简单的REST协议从客户端到服务器来回移动。 解决方案正常运行没有任何问题。 问题: 我为“Person”设置了一个父类“PropertyChangedBase”,以实现NotifyOfPropertyChanged()。 public class Person : PropertyChangedBase { public int Id {get;set;} private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; NotifyOfPropertyChange(() => FirstName); } } … } […]

JSON.Net Xml序列化误解了数组

我有一些自动生成的xmls,其中xml的某些部分可能有多行,有些可能没有。 结果是,如果有一行返回一个json节点,并且如果我有多行,则返回一个带有json节点的数组。 xmls可能看起来像这样 Testing 0 或者有多行 Update Documentation 0.5 2013-01-31 00:00:00 2013-01-01 00:00:00 Write jQuery example 0.05 2013-06-30 00:00:00 2013-01-02 00:00:00 使用时将这些序列化为JSON JsonConvert.SerializeXmlNode(xmldoc, Formatting.Indented); 第一个xml变成了这个 { “List”: { “Content”: { “Row”: { “@Index”: “0”, “Title”: “Testing”, “PercentComplete”: “0”, “DueDate”: null, “StartDate”: null } } } } 第二个这个 { “List”: { “Content”: { “Row”: [{ “@Index”: […]

ASP.NET WebService使用XML标记包装我的JSON响应

我不确定我错过了什么,我错过了什么。 我正在构建一个ASP.NET 2.0(在.Net 3.5框架上)Web应用程序,我正在包含一个Web服务。 请注意,这不是 MVC项目。 我希望公开一个返回JSON字符串的方法; 格式化以提供jqGrid jQuery插件。 这是我在我的服务中实现的初步测试方法:感谢( Phil Haack的MVC指南 ) [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string getData() { JavaScriptSerializer ser = new JavaScriptSerializer(); var jsonData = new { total = 1, // we’ll implement later page = 1, records = 3, // implement later rows = new[]{ new {id = 1, cell […]

ASP.NET web api无法获得application / x-www-form-urlencoded HTTP POST

我是web-api的新手。 我想使用web-api接收HTTP POST数据。 内容类型是application/x-www-form-urlencoded ,请求正文如下: data={“mac”:”0004ED123456″,”model”:”SG6200NXL”} (JSON格式)。 我的控制器是这样的: public void Post([FromBody]string formData) { data.Add(formData); } 但是formData始终为null。 仅当我将请求正文更改为: ={“mac”:”0004ED123456″,”model”:”SG6200NXL”} 我可以找到{“mac”:”0004ED123456″,”model”:”SG6200NXL”}保存在我的formData字符串中。 所以我的问题是我应该如何接收格式的数据: data={“mac”:”0004ED123456″,”model”:”SG6200NXL”} ? 有没有一种简单的方法可以将JSON淡化为C#? 感谢帮助! 更新:我试图使用模型,但它仍然不适合我。 我的模型是: public class Device { public string mac { get; set; } public string model { get; set; } } 我的HTTP POST请求是: 标题: User-Agent: Fiddler Content-type: application/x-www-form-urlencoded Host: localhost:52154 Content-Length: […]