json.net

Name array elements in Json.NET?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 09:13:43
问题 Using Json.NET 10.0.3. Consider the following sample: class Foo { [JsonProperty("ids")] public int[] MyIds { get; set; } } Obviously, the elements of the array are unnamed. Now consider the following json : { "ids": [{ "id": 1 }, { "id": 2 } ] } And then we try to parse it: var json = @"{""ids"":[{""id"":1},{""id"":2}]}"; var result = JsonConvert.DeserializeObject<Foo>(son); Parsing the above fails with the following message: Newtonsoft.Json.JsonReaderException: Unexpected character

How do you check if a JSON array is an array of objects or primitives recursively

一世执手 提交于 2019-12-13 08:38:44
问题 The title is exactly what I meant All the questions on Stackoverflow asks for whether if the json data is an object or array but what I'm looking for is to see if I can find out if the array is an array of primitive types or objects. Currently, i already can identify if its an array or not, just that I'm unable to convert if it is not an array of strings. This code is wrapped in a for loop, where it is (var comArrEl in comArr), where comArr is an array of strings. This array stores something

How can I create a JSONPath filter expression containing both AND and OR operators?

匆匆过客 提交于 2019-12-13 08:27:37
问题 I have a requirement where i am trying to select objects inside a JSON string by filtering on the presence and/or values of multiple properties of objects inside a JSON array. Here is an example of my JSON: {'Fields':[{ "Sub_Status": "Pending", "Status": "Pending", "Patient_Gender": "M" }]} I want to check this json string using query like this (below query is a SQL query) string query = TRIM(UPPER(Status)) IN ('PENDING', 'DISPENSED','SHIPMENT') AND TRIM(Patient_Gender) IS NOT NULL string

JSON.Net Cannot deserialize the current JSON array

倾然丶 夕夏残阳落幕 提交于 2019-12-13 07:28:14
问题 I'm attempting to make a program for LoL that would allow users to view specific stats for a player. However, I'm having issues.. The error I'm getting is. Additional information: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'WindowsApplication1.Form1+Rootobject' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. This is the code that I have so far. Public Class Rootobject Public Property games As Integer Public Property winPercent

Json.Net Deserialize Returning Nulls

谁都会走 提交于 2019-12-13 07:26:06
问题 I'm using the Petfinder API and trying to return a root object in my C# code. I used the Json class generator to generate the classes, but the Deserialize function is returning nulls. This is my C# code: using (var client = new WebClient()) { var json = new WebClient().DownloadString("http://api.petfinder.com/shelter.getPets?format=json&key=<key>&id=<id>"); Petfinder deserializedPet = JsonConvert.DeserializeObject<Petfinder>(json); } The Petfinder object is defined as: internal class

Cannot deserialize JSON object into type 'System.Collections.Generic.List'

拈花ヽ惹草 提交于 2019-12-13 07:16:49
问题 i'm trying to deserialize a json string pulled from the web using json.net, but i am getting a Cannot deserialize JSON object error. Here is the json string { "metadata": { "page": 1, "perPage": 23, "count": 23 }, "results": [ { "id": 9, "name": "Breaks", "slug": "breaks", "subgenres": [] }, { "id": 10, "name": "Chill Out", "slug": "chill-out", "subgenres": [] }, { "id": 12, "name": "Deep House", "slug": "deep-house", "subgenres": [] }, { "id": 16, "name": "DJ Tools", "slug": "dj-tools",

Losing non printable ascii character (group separator) when deserializing with JsonConvert.DeserializeObject (Newtonsoft.Json)

余生长醉 提交于 2019-12-13 07:15:36
问题 I have a frustrating problem that I'm unable to solve. I am using Newtonsoft.Json to deserialize some .json data. I can plainly see in the raw json string that there are character sequences { '\\', 'u', '0', '0', '1', 'd' } This represents "group separator" (ascii 29 or 0x1D). However, when I deserialize using JsonConvert.DeserializeObject<> these character sequences are not put correctly into their objects. What is put in instead is simply 1D. That is if you look at the character array you

Deserialize JSON to an array of objects, instead of to one object list

时光怂恿深爱的人放手 提交于 2019-12-13 07:11:50
问题 Apologies for the probably confusing title. I'm new to JSON and I'm working on a Web Application with a piece of software which interfaces with the API. I have control of both. My applications needs to enumerate a list of "Clients" and their "Projects". Currently it returns the following: { "clients": [ { "client_id": "1", "client_name": "Client1", "projects": [ { "client_project_id": "1", "client_project_title": "WidgetsA", "client_project_client": "1", "client_project_status": "1" }, {

Convert objects to JSON in C#

两盒软妹~` 提交于 2019-12-13 07:06:46
问题 I have a class: public class StatististikaByCustomer { public string data { get; set; } // Array or String? public string xkey {get;set;} public Array ykey {get;set;} public Array labels {get;set;} } How can I get JSON like this? { "data":[ { "timeinterval":"2015-10-22T00:00:00", "Firm":4, "Firm1":4, "Firm2":22, "Firm3":30, "Firm4":19 }, { "timeinterval":"2015-10-23T00:00:00", "Firm":2, "Firm1":5, "Firm2":29, "Firm3":34, "Firm4":219 } ], "xkey":"timeinterval", "ykey":["Firm","Firm1","Firm2",

Deserialize empty json propertyname

為{幸葍}努か 提交于 2019-12-13 07:03:46
问题 I have a json object coming from a web api which looks something like this: {"":[{"id":1, "name":"name1"}, {"id":2, "name":"name2"}]} and I have corresponding C# class for deserialize: public class Person { public int id { get; set; } public string name { get; set; } } public class RootObject { public List<Person> Persons { get; set; } } but whenever I deserialize using Json.NET the Persons property in RootObject class is always null. var c = JsonConvert.DeserializeObject<RootObject>(response