json.net

Json.net Deserialize to JObject derived type

╄→гoц情女王★ 提交于 2019-12-11 06:02:07
问题 public class A : JObject {} and I have the folowing deserialization code using (StreamReader responseStreamReader = new StreamReader(stream)) { using (JsonReader reader = new JsonTextReader(responseStreamReader)) { JsonSerializer serializer = new JsonSerializer(); return serializer.Deserialize<A>(reader); } } But it throws Invalid Cast Exception in fact the deserializer just need to create new A() instead of new JObject() and do exactly the same after that, it would be enough for me. How can

Cannot access methods Newtonsoft.JSON .Net Core 2.*

杀马特。学长 韩版系。学妹 提交于 2019-12-11 06:01:50
问题 I'm have a solution with multiple projects all using .Net Core 2.1 (VS 2017). I can use Newtonsoft.JSON.JsonConvert in my web project without any problem for serializing and deserializing objects. Another project in the same solution has the same Nuget packages (version and SDK) as my web project. Intellisense recognizes JsonConverter, but the only method that shows is Equals, so no SerializeObject or DeserializeObject. When I open the JsonConvert Definition within my console application it

JSON.Net parse Facebook Graph JSON for all messages

南笙酒味 提交于 2019-12-11 05:55:04
问题 Using JSON.Net (http://www.newtonsoft.com/json/help/html/LINQtoJSON.htm) and the following code: @using Newtonsoft.Json; @using Newtonsoft.Json.Linq; @{ var url = "https://graph.facebook.com/v2.2/me&fields=id%2Cname%2Cposts.limit(3)&format=json&method=get&pretty=0&suppress_http_code=1"; var syncClient = new WebClient(); var content = syncClient.DownloadString(url); JObject facebook = JObject.Parse(content); //To-Do: Get all messages as list<string> using LINQ for JSON // Ex: IList<string>

Using a custom JSON formatter for Web API 2

非 Y 不嫁゛ 提交于 2019-12-11 05:53:01
问题 I have a custom JSON formatter that removes the time stamp from a DateTime value. The following is the code: var isoJson = JsonConvert.SerializeObject(value, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd" }); return isoJson; When I use that formatter, the string is serialized twice by the above formatter and because of JSON.Net formatter in my WebApiConfig file. The following is the code for the JSON.Net formatter: config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new

Displaying Specific Fields from Facebook Graph API JSON

三世轮回 提交于 2019-12-11 05:47:55
问题 I'm trying to simply display the list of members in a specific group using the Facebook Graph API. I'm using Newtonsoft.JSON. Here is the results of my url query: Graph API Results I used a JSON class generator and it gave me this: public class Datum { public string name { get; set; } public string id { get; set; } public bool administrator { get; set; } } public class Cursors { public string before { get; set; } public string after { get; set; } } public class Paging { public Cursors cursors

Parsing Complex JSON without reflected objects?

↘锁芯ラ 提交于 2019-12-11 05:39:07
问题 I am using an API that outputs JSON objects with many attributes including sub-objects. So far all of the examples that I have found for JSON in C# assume that the .Net object has been serialized to JSON and can be deserialized back into the .Net object. I am trying to find a solution where I can read the JSON into some generic object that I can then manually assign values to my Business Object properties by selecting the values from the generic objects. Possibly something like ADO.Nets

Extract nested values from newtonsoft JSON with C# [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-11 05:37:40
问题 This question already has answers here : C# Create a .NET object for JSON serialization and deserialization [duplicate] (2 answers) Closed 2 months ago . I am new to C#. I have the following JSON parsed with newtonsoft: {"Results":{"output1":{"type":"table","value":{"ColumnNames":["Purchased Bike","Scored Labels"],"ColumnTypes":["String","Double"],"Values":[["value","0.55503808930127"]]}}}} I want to extract the value 0.555... which is under the "Values" level. I was thinking about converting

Deserialize JSON using Newtonsoft and biding View (MVVM)

邮差的信 提交于 2019-12-11 05:33:42
问题 I'm a beginner in C # and Xamarin. I'm trying to deserialize json arrays with newtonsoft? Here is my json file: { "next": { "$ref": "http://192.168.0.100:8080/ords/hr/employees/?page=1" }, "items": [ { "empno": 7369, "ename": "SMITH", "job": "CLERK", "mgr": 7902, "sal": 800, "deptno": 20 }, { "empno": 7934, "ename": "MILLER", "job": "CLERK", "mgr": 7782, "sal": 1300, "deptno": 10 } ] } Her is my model class: public class RootObject { [JsonProperty("items")] public Item[] Items { get; set; }

Creating reduced json from a bigger json in c# [duplicate]

情到浓时终转凉″ 提交于 2019-12-11 05:24:34
问题 This question already has an answer here : How to perform partial object serialization providing “paths” using Newtonsoft JSON.NET (1 answer) Closed 6 months ago . I have a json that is coming from the server similar to this (with multiple nested json objects). { "employee": [{ "fullname": { "firstname": "abcd", "lastname": "defg" }, "project": [{ "projectname":"abcd_1", "datejoined": "2019-06-18T01:29:38.6013262+00:00", "projectmanager": "abcdM1", }, { "projectname":"abcd_2", "datejoined":

Parsing JSON dates that end in T24:00:00Z

你离开我真会死。 提交于 2019-12-11 05:19:53
问题 I'm hitting an API which is returning to me ISO dates using 24:00:00 as the time portion of the datetime. I'm using JSON.NET, but when I try to parse this datetime, it is currently blowing up. The return from the API is the following: { "endTs":"2015-07-30T24:00:00Z" } I would expect to parse this as "2015-07-31 12:00:00AM" , but instead I get the following error currently: Could not convert string to DateTime: 2015-07-30T24:00:00Z. Path 'endTs'... 回答1: Update This is fixed in Json.NET 8.0.1.