json.net

Converting arbitrary json response to list of “things”

点点圈 提交于 2019-12-08 02:24:03
问题 I'm having an unusual problem. It might not be a very realistic scenario, but this is what I have gotten myself into, so please bear with me. I have an API that returns Json and I'm using Json.NET to process the Json response. The problem is that the API can return a number of things and I have to be able to deserialize the response the following way: The API can return a single Json object. In this case I have to deserialize it into an ExpandoObject and put it into a List<dynamic> . The API

JSON.NET exception when deserializing an array of GUIDs

和自甴很熟 提交于 2019-12-08 01:32:44
问题 I'm using JSON.NET to deserialize AJAX HTTP requests sent in from the browser, and am running into problems with web service calls that use a Guid[] as a parameter. This worked fine when I used the built in .NET serializer. First off, the raw bytes in the stream look like this: System.Text.Encoding.UTF8.GetString(rawBody); "{\"recipeIds\":[\"d9ede305-d244-483b-a435-abcf350efdb2\"]}" I then call: Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); parameters[0] =

Parsing JSON with JSON.NET

久未见 提交于 2019-12-08 00:48:07
问题 I have a JSON string: {"responseData": {"results": [ {"GsearchResultClass": "GblogSearch", "title":"\u003cb\u003eParis Hilton\u003c/b\u003e shops at Sydney Michelle boutique in the Beverly Glen \u003cb\u003e...\u003c/b\u003e", "titleNoFormatting":"Paris Hilton shops at Sydney Michelle boutique in the Beverly Glen ...", "postUrl":"http://www.celebrity-gossip.net/celebrities/hollywood/paris-hilton-sydney-michelle-stockup-215844/", "content":"\u003cb\u003eParis Hilton\u003c/b\u003e shops at

How to recursively deserialize dynamic JSON into .NET objects using Json.NET on windows phone

≯℡__Kan透↙ 提交于 2019-12-08 00:44:44
问题 I am receiving some dynamic JSON in a windows phone app and I need to be able to completely deserialize it into objects that can be saved into isolated storage. For this application it would be best to avoid becoming locked into a class structure because I cannot predict exactly what type of JSON I will be getting back from a server. Here is an example of how I am using Json.NET to deserialize: JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString); In this example the Values

AssemblyLoadException in PostSharp on release build

心已入冬 提交于 2019-12-07 23:55:54
问题 I have a couple of projects that all include the json.net 6.0.3 NuGet package. When I add: using Newtonsoft.Json; I get the following error when building: 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: Unhandled exception (3.1.48.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: Cannot find assembly 'newtonsoft.json, version=4.5.0.0, culture=neutral, publickeytoken=30ad4fe6b2a6aeed'. [Version mismatch] 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: ===========

Exception parsing json with System.Text.Json.Serialization

瘦欲@ 提交于 2019-12-07 22:58:24
问题 My sample code is very simple: using System.Text.Json.Serialization; using Newtonsoft.Json; public class C { public C(string PracticeName) { this.PracticeName = PracticeName; } public string PracticeName; } var x = new C("1"); var json = JsonConvert.SerializeObject(x); // returns "{\"PracticeName\":\"1\"}" var x1 = JsonConvert.DeserializeObject<C>(json); // correctly builds a C var x2 = System.Text.Json.Serialization.JsonSerializer.Parse<C>(json); the last line raises: Exception thrown:

Using Newtonsoft.Json, how do I deserialize JSON to a type with an IEnumerable property containing an interface type?

前提是你 提交于 2019-12-07 22:01:38
问题 I am consuming a RESTful Web service sending JSON, that I try to deserialize using HttpContent.ReadAsAsync<T> . The type I try to deserialize to declares a property that returns an IEnumerable containing an interface type. This code snippet demonstrates the kind of type I'm trying to deserialize to: public class Data { public IEnumerable<IChild> Children { get; set; }; } The problem is that Newtonsoft.Json, underlying HttpContent.ReadAsAsync<T> doesn't understand how to deserialize objects of

Coded UI Test now gets error about Newtonsoft.json not being found

泪湿孤枕 提交于 2019-12-07 20:02:31
问题 I have a simple Coded UI test to log into an application. The test is data driven and uses data from TFS. We are using a TfsTestAgent user (that has admin privileges) that is on both the server and the agent systems. When I execute the test, I see the following error: The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in

dynamically deserialize json into any object passed in. c#

不想你离开。 提交于 2019-12-07 19:44:47
问题 I'm trying to do is deserialize json into an object in c#. What I want to be able to do is pass any object get it's type and deserialize the json into that particular object using the JSON.Net library. Here are the lines of code. Object someObject1 = someObject; string result = await content.ReadAsStringAsync(); return JsonConvert.DeserializeObject<someObject1.GetType()>(result); The last line throws an exception of operator '<' cannot be applied to operands of type 'method group' How do I

C# Json.NET WCF Rest DateTime Format

梦想与她 提交于 2019-12-07 18:58:41
问题 Take a look at the following example code, I would like the output to be a WCF date format "/Date(1237951967000)/" or the time zone variant. class Program { public class Test { public DateTime Date { get; set; } } static void Main(string[] args) { var test = new Test { Date = DateTime.Now }; var json = JsonConvert.SerializeObject(test); Console.WriteLine(json); } } Here is the output: {"Date":"2013-05-09T11:17:38.7990259-07:00"} How can I adjust the above code to give the desired format? {