Tag: json

将树类转换为更简单的Tree类,并将Serialize转换为Json维护结构

好的,所以我有一个类似这样的类: public class Channel { public Guid Guid{get;set;} public string Title{get;set;} /* GOT A LOT MORE PROPERTIES IN THIS SPACE */ public Guid Parent {get;set;} public List Children{get;set;} } 我还有一个List (总共约650个Channels ) ROOT频道包含大约6个频道,每个频道包含,儿童等。 正如你在Channel的代码中看到的那样,还有很多其他的属性,我不想在这种情况下序列化。 也就是说,所有Data Contracts都已在基类中定义,并且我不会/不能仅为此操作更改它们。 所以,你问我的问题是什么? 我需要将List或List序列化为JSON并维护Tree结构。 如果不可能,至少,我如何序列化List到JSON维护结构? 编辑:我正在使用Newtonsoft.Json

JSON.Net序列化器忽略JsonProperty?

我有以下实体类: public class FacebookComment : BaseEntity { [BsonId(IdGenerator = typeof(ObjectIdGenerator))] [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] [JsonProperty(“_id”)] public ObjectId Id { get; set; } public int? OriginalId { get; set; } public DateTime Date { get; set; } public string Message { get; set; } public string Sentiment { get; set; } public string Author { get; set; } } […]

如何让我的aspx web方法将列表作为JSON对象返回?

我有一个返回对象的Web方法。 我需要将此对象转换为JSON对象,以便我可以通过我的Android应用程序使用它。 因此,我的问题是,为了将以下内容作为JSON对象返回,我需要做出哪些更改? aspx代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Script.Services; namespace WebService4 { /// /// Summary description for Service1 /// [WebService(Namespace = “http://tempuri.org/”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class […]

如何更改asp.net mvc格式化JSON的方式?

我有这个型号 : public class Person { public string Name { get; set; } public int Age { get; set; } public List Colors { get; set; } } public class Color { public int ColorId { get; set; } public string Name { get; set; } } 和asp.net MVC的return Json(…)给了我这个: [{“Name”:”JC”,”Age”:24,”Colors”:[{“ColorId”:1,”Name”:”Red”},{“ColorId”:2,”Name”:”Blue”}]}, {“Name”:”Albert”,”Age”:29,”Colors”:[{“ColorId”:2,”Name”:”Blue”}]}] 当我尝试返回一种类型: List 但我想要这样的东西(如果可能的话): […]

JSON.Net的反序列化返回’null’

我正在使用JSON.Net来反序列化JSON字符串。 JSON字符串是 string testJson = @”{ “”Fruits””: { “”Apple””: { “”color””: “”red””, “”size””: “”round”” }, “”Orange””: { “”Properties””: { “”color””: “”red””, “”size””: “”round”” } } } }”; 我的代码是 public class Fruits { public Apple apple { get; set; } public Orange orange { get; set; } } public class Apple { public string color { […]

在linkedin服务器上暂时不可用

我是新手使用linkedin编程并尝试获取一些用户数据,但是我无法进一步了解https://www.linkedin.com/uas/oauth2/accessToken ,我得到了这个响应: {“error”:“temporary_unavailable”,“error_description”:“授权服务器当前无法处理请求:RestException {_response = RestResponse [headers = {X-LinkedIn-Error-Response = true,Content-Length = 6936, X-Restli-Protocol-Version = 1.0.0,Server = Jetty(8.1.8.v20121106)},status = 404,entityLength = 6936]}“} 我使用以下带参数的url: https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=AQR4LKsR8tswI4o-Ej0bE6vg1fhAZntPuT26CFMFEhZZh7zFkLM7PyxRRp5XEzZ-Y45vIBwZam8zDncMECldDrCSJI8WKNlxrR5gsAcxmkga0ZzIM38&redirect_uri=http://localhost:30731/redirect.aspx&client_id=OAuth用户令牌&client_secret = OAuth的用户秘密 我在C#中得到的错误是服务器是不可用的,它与JSON消息相对应。 有人确实知道解决方案或有相同的错误或解决方案吗?

如何从跨域API获取数据

我正在尝试从不同域中的API获取数据,但是我收到此错误: XMLHttpRequest无法加载https://www.bitstamp.net/api/ticker/ 。 请求的资源上不存在“Access-Control-Allow-Origin”标头。 因此不允许原点’localhost’访问。 我试图在标题中添加它,但它仍然无法正常工作: Access-Control-Allow-Origin: https://www.bitstamp.net 这是我的JavaScript: var ticker = “https://www.bitstamp.net/api/ticker/”; $.ajax({ dataType: “json”, url: ticker, type: “POST”, crossDomain: true, scriptCharset: “utf-8” }); 我无法使用JSONP,因为该网站不支持此function。 如何在不同的域上使用JSON从API接收数据? 我想用JavaScript或C#来做这件事。

Unity JSON将数据添加到现有的json数据

我正在为多个数据库设置创建索引。 每次创建新数据库时,我都需要一个索引,以便该人可以连接到他们想要处理的数据库。 将索引保存在json文件中后,一旦我再次加载它,如何在不删除现有数据的情况下添加它? 我看过的大多数教程都告诉你如何保存和加载但不能用现有数据做什么。 谢谢! 虽然我正在使用JSONUtility,因为这是一个非常简单的操作,但我不反对任何其他库的建议。

C#将每列的值转换为数组

我想转换一个C#对象或数据表,使每个列成为一个键,值成为一个数组 year productOne ProductTwo ProductThree 2010 1 2 3 2011 10 20 30 2012 100 200 300 2013 1000 2000 3000 我期待生成以下JSON输出。 请记住,行和列都不是动态的。 [{ name: productOne , data: [1,10,100,1000] },{ name: productTwo , data: [2,20,200,2000] },{ name: productThree , data: [3,30,300,3000] }]

将json对象发布到ASP MVC无法正常工作

我正在尝试将自定义Json对象发布到ASP.NET MVC控制器,但无法正常工作。 我的JS代码是: var myData = { “Message”: “Another message”, “Value”: 4, “FirstItem”: { “ItemName”: “Este es el primer Item” }, “SecondItem”: { “ItemName”: “Este es el segundo Item” } }; $(‘.clickeable’).click(function () { $.ajax({ type: ‘POST’, dataType: ‘json’, data: myData, url: ‘@Url.Action(“PostSomething”)’, success: function () { console.info(‘Success’); }, error: function () { console.info(‘Error’); } […]