json.net

Json.net map dynamic property to a fixed one [duplicate]

霸气de小男生 提交于 2019-12-12 19:14:18
问题 This question already has answers here : How to get the name of <T> from generic type and pass it into JsonProperty()? (3 answers) Does Json.NET cache types' serialization information? (1 answer) Closed last year . QuickBooks Online uses for their API the following response: { "QueryResponse": { "Customer": [ { "GivenName": "Test" }, { "GivenName": "Test 2" } ], "startPosition": 1, "maxResults": 2 }, "time": "2018-08-11T16:12:10.808-07:00" } I'm trying to create a C# model from this: public

newtonsoft json package requires reinstall every time i open code

房东的猫 提交于 2019-12-12 19:07:03
问题 I'm writing C# code in a script task in SSIS. I need to use the Newtonsoft JSON package in the code so i have installed it from NuGet. When it is first installed it works fine, but when I close my code and re-open it to make a change, I have to re-install the package using update-package -Reinstall as per the Some NuGet packages are missing from the solution in Visual Studio Application post. Why do I have to do this every time? Am I doing something wrong? Thanks for your help. 回答1: I found

Convert JSON String from Camel case to Pascal case using C#

試著忘記壹切 提交于 2019-12-12 19:06:32
问题 I'm having a JSON string, it has Key in the form of Camel-case but I need to convert the Key to Pascal-case. Actual JSON String string jsonString = "{\"personName\":{\"firstName\":\"Emma\",\"lastName\":\"Watson\"}}"; Expected JSON String : Needs to convert from the above JSON string. string jsonString = "{\"PersonName\":{\"FirstName\":\"Emma\",\"LastName\":\"Watson\"}}"; Kindly assist me how to convert this using C#. 回答1: Because I can't sleep. If you define the following static class of

How to get detailed position information from JsonTextReader

天涯浪子 提交于 2019-12-12 18:32:50
问题 I am working with a third-party system that provides audio files and various pieces of data about the audio files. The problem I am dealing with is that the pieces of data are JSON objects, that are sprinkled essentially randomly throughout the binary data of the audio file. No information is provided for where the JSON is and the binary data is. So, one way to deal with this is to simply go through the file, and every time I encounter { , I try to parse out a json object from that point. If

Prevent JSON.NET Xml converter from prefixing attributes with '@' [duplicate]

帅比萌擦擦* 提交于 2019-12-12 18:31:35
问题 This question already has answers here : JSON.NET and Replacing @ Sign in XML to JSON converstion (10 answers) JSON.net has @ in the attribute names? (1 answer) Closed 6 years ago . I'm trying to convert some XML data into JSON to use with KnockoutJS. After a bit of research I decided to go with JSON.NET to convert my XNode tree to a JSON String. I convert the XML tree by calling JsonConvert.SerializeXNode(result, Newtonsoft.Json.Formatting.Indented, True) which gives me something like

Omit type for dynamic property without modifying class?

独自空忆成欢 提交于 2019-12-12 18:14:25
问题 I have a bunch of domain objects that I serialize, send to other applications and then deserialize using Json.Net . These objects may have properties that are Defined as an abstract base class with multiple derived classes Dynamic Properties I've used TypeNameHandling.Auto , which adds the $type property to types that differ from the declared type. However, this setting has an unwanted side effect on my dynamic properties, namely that the types of them gets declared, too. In the example below

How to ignore an array item during deserialization of JSON string

巧了我就是萌 提交于 2019-12-12 17:20:34
问题 It seems to be very simple, but I just can't figure out how to do it. I use an external api to get JSON results (using Newtonsoft.JSON), problem is a poor design which leaves me with a array with mixed types like this: {"data":["Monday 13 january", {"id":"1234aa","name":"teamA"},{"id":"1234bb","name":"teamB"}, "Tuesday 14 january", {"id":"1234aa","name":"teamA"}]} This will result in an object like: public class RootObject { public List<object> data { get; set; } } I want to ignore those date

Deserialize JSON into custom list

心已入冬 提交于 2019-12-12 17:19:15
问题 I have this json: var x = [ [99,"abc","2dp",{"GroupNum": 0,"Total":[4, 1]}], [7,"x","date"], [60,"x","1dp",{"GroupNum": 1}], ... ] The following rules exist (let i refer to the inner list index): x[i][0] - mandatory item - always an integer x[i][1] - mandatory item - always a string x[i][2] - mandatory item - always a string x[i][3] - optional item - when it exists then it has the following rules: x[i][3].GroupNum - mandatory field - always an integer x[i][3].Total - optional field - when it

Converting PHP array of arrays to C#

跟風遠走 提交于 2019-12-12 17:15:21
问题 I am writing a C# client for a 3rd party API (I'm using the RestSharp nuget package). Their documentation contains PHP examples which I must translate to C#. Most of their samples are simple enough and I have been able to convert them to C# but I am struggling with one of them because it accepts an array of arrays. Here's the sample from their documentation: $params = array ( 'user_key' => 'X', 'client_id'=> 'X, 'label' => array( array( 'language' => 'en_US', 'name' => 'English label', ),

How to filter a non-array in JsonPath

你离开我真会死。 提交于 2019-12-12 17:10:01
问题 Using the following JSON (from http://jsonpath.com): { "firstName": "John", "lastName" : "doe", "age" : 26, "address" : { "streetAddress": "naist street", "city" : "Nara", "postalCode" : "630-0192" }, "phoneNumbers": [ { "type" : "iPhone", "number": "0123-4567-8888" }, { "type" : "home", "number": "0123-4567-8910" } ] } I would like to get the root object only if firstName is John. I have tried these inputs and many other similar ones: $.[?($.firstName == 'John')] $.[?($.'firstName' == 'John'