Tag: json

未定义或导入预定义类型“System.Object”.net 4.6

我正在使用MVC 5和.net 4.6来创建我的移动应用程序也可以连接的Web API。 每当我构建项目时,我都会收到数百个错误,告诉我我需要添加已经存在的引用,而且我的项目中的每个类型都不存在。 这些错误的一些例子:(不包括标题中的那个) 我尝试过的: 通过nuGet添加了对System.Runtime的引用。 ( 这个问题的建议。) 从project.json文件中的框架中删除了aspnetcore50。 (另一个建议, 这个问题 。) 重新启动我的机器VS2015。 浏览nuGet包管理器并将项目中的每个包升级到最新版本。 实际上确保我可以在解决方案资源管理器的参考节点中看到引用。 更新: – 我的 project.json文件看起来像这样。 (根据Karls答案修改后。错误列表现在已降至十,但它们仍然与以前相同。) { “commands”: { “web”: “Microsoft.AspNet.Hosting –server Microsoft.AspNet.Server.WebListener –server.urls http://localhost:5000” }, “dependencies”: { “Microsoft.AspNet.Server.IIS”: “1.0.0-beta5”, “Microsoft.AspNet.Server.WebListener”: “1.0.0-beta5”, “Microsoft.AspNet.Diagnostics”: “1.0.0-beta5”, “Microsoft.AspNet.Mvc”: “6.0.0-beta5”, “System.Runtime”: “4.0.20-beta-23019” }, “exclude”: [ “wwwroot”, “node_modules”, “bower_components” ], “frameworks”: { “dnx451”: { […]

在MVC Web Api 4 Beta中从Json中删除Null属性

我正在序列化对象并从我的Web服务返回json。 但是,我试图从序列化的json中省略null属性。 有没有办法做到这一点? 我正在使用Web Api MVC 4 beta。

.Net 4.5中的任何新function都可以处理更好的JSON?

.NET 4.5和VS2012中的JSON处理有什么新东西比DataContractJsonSerializer更好吗? 我见过一些关于System.JSON的内容。 但它更好吗? 我知道也有JSON.NET,但我不确定是否允许我将另一个.dll添加到我的项目中。

动态读取文件中的资源

我一直在使用resx文件作为静态字符串,以便有一个更改它们的中心位置。 问题是我在构建和部署项目后无法更改它们。 在部署之后,我想要更改一些字符串,而不重新启动进程(因此.config文件已经用完)。 可以编写有效解析配置文件(XML / JSON / YAML /?)的代码,例如将结果缓存X秒或使用FileSystemWatcher监视它的变化,但是已经完成了这样的事情? 编辑:使用Json.NET和Rashmi Pandit指向CacheDependency的指针我编写了这个JSON解析类,它缓存解析后的结果直到文件被更改: public class CachingJsonParser { public static CachingJsonParser Create() { return new CachingJsonParser( HttpContext.Current.Server, HttpContext.Current.Cache); } private readonly HttpServerUtility _server; private readonly Cache _cache; public CachingJsonParser(HttpServerUtility server, Cache cache) { _server = server; _cache = cache; } public T Parse(string relativePath) { var cacheKey = […]

Google财经,如何获取流式传输的JSON数据?

我试着早点解释一下,但显然失败了! 因此,如果您打开了Google财经图表,例如: http://www.google.com/finance?q=INDEXNASDAQ:.IXIC 我想以某种方式在C#中使用(HttpWebRequest)对象,以便我可以抓取google发送到页面的小数据来更新图形。 有朋友提到这是JSON吗? 我试图使用下面的代码示例,但即使我将keep alive属性设置为’true’,它仍然无法工作: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.keepalive.aspx#Y369

无法反序列化当前的JSON对象,为什么?

我正在尝试使用WebApi从我的数据库中获取Employees列表,使用此代码:这是我的客户端MVC应用程序的代码: string u = “http://localhost:1411/api/EmployeeAPI”; Uri uri = new Uri(u); HttpClient httpClient = new HttpClient(); Task response = httpClient.GetAsync(uri); Task.WaitAll(response); HttpResponseMessage resposta = response.Result; var msg = resposta.Content.ReadAsStringAsync().Result; Employee[] employees = JsonConvert.DeserializeObject(msg); return View(employees); 这是我的WebAPI的代码: public IEnumerable GetEmployees() { return db.Employees.AsEnumerable(); } 但是这个错误不断出现,我无法理解为什么: 无法将当前JSON对象(例如{“name”:“value”})反序列化为类型“DataAccess.Employee []”,因为该类型需要JSON数组(例如[1,2,3])才能正确反序列化。 要修复此错误,请将JSON更改为JSON数组(例如[1,2,3])或更改反序列化类型,使其成为普通的.NET类型(例如,不是像整数这样的基本类型,而不是类似的集合类型可以从JSON对象反序列化的数组或List。 JsonObjectAttribute也可以添加到类型中以强制它从JSON对象反序列化。 路径’消息’,第1行,第11位。 我的员工类: namespace DataAccess { using System; using […]

使用JsonConvert.DeserializeObject反序列化派生对象列表

我有这个对象 public class ConversationAPI { [JsonProperty(PropertyName = “lU”)] public DateTime LastUpdated { get; set; } [JsonProperty(PropertyName = “m”, TypeNameHandling = TypeNameHandling.All)] public List Messages { get; set; } } 我作为json从API发送,并在我的客户端应用程序中反序列化。 The List Messages property contains either [Serializable] public class Message { [JsonProperty(PropertyName = “t”)] public string Text { get; set; } [JsonProperty(PropertyName = “ty”)] public […]

如何基于Json反序列化的JArray数据创建DataTable?

我已经停止了JArray数据。 我需要根据Jarray中的列名动态创建一个数据表,之后我需要插入数据。 你能帮我做一下这个操作吗? {[ { “PID”: 3, “FirstName”: “parveen”, “LastName”: “a”, “Gender”: “male” }, { “PID”: 8, “FirstName”: “ramarao”, “LastName”: “M”, “Gender”: “male” } ]} 提前致谢 普尔纳

通过实施Web服务为Alexa托管自定义技能

我正在开发一个Web服务,用于处理Alexa发送的请求,并在.net框架中回复特定的响应。 Alexa以JSON格式向您的服务发送请求正文,如下所示: { “version”: “string”, “session”: { “new”: true, “sessionId”: “string”, “application”: { “applicationId”: “string” }, “attributes”: { “string”: {} }, “user”: { “userId”: “string”, “accessToken”: “string” } }, “context”: { “System”: { “application”: { “applicationId”: “string” }, “user”: { “userId”: “string”, “accessToken”: “string” }, “device”: { “supportedInterfaces”: { “AudioPlayer”: {} } } }, “AudioPlayer”: […]

Json.Net可以嵌入到可执行文件中吗?

我将Netwonsoft.Json库的’Embed Interop Types’属性设置为true ,它返回一个错误: Cannot embed interop types from assembly ‘c:\path\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll’ because it is missing either the ‘ImportedFromTypeLibAttribute’ attribute or the ‘PrimaryInteropAssemblyAttribute’ attribute c:\path\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 它看起来像在Newtonsoft.Json库中寻找缺少的引用,但我不完全确定。 是否有可能将Json.Net嵌入到可执行文件中?