json.net

Parsing dynamic JSON string into string in C# using JSON.NET

放肆的年华 提交于 2019-12-06 09:37:05
问题 This is my first little project on C# and JSON. I'm asked to parse a JSON file into the following: I'm trying to create a windows form whose body will contain the content of a JSON string in the following format: Name of the object (Label) name of the attribute of the object - (TextBox) editable value (Label) name of the attribute of the object - (TextBox) editable value ... I have approx 35 attributes per object in the json file and 8 objects. There are around 50 different attributes in

Querying JSON with JSONPath or SelectTokens? With JSON.NET in C#

人走茶凉 提交于 2019-12-06 08:46:33
问题 I am trying to use the Newtonsoft.Json.Net in c#. The following is part of JSON file that I need to retrieve data out of: { "video":{ "local_recording_device":{ "codecs":null }, "preferred_string":"___PREFERRED___", "streams":{ "99176901":{ "id":"99176901", "name":"PTZ Camera", "site":"someone", "email":"someone@awebsite.com", "codec":"VP8 HD1 (720p)", "local":true, "screen":false, "fit_to_window":true, "stay_on_top":false, "layout":0, "native_width":1280, "native_height":720, "window_width"

Parsing JSON with JSON.NET

穿精又带淫゛_ 提交于 2019-12-06 08:15:11
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 Sydney Michelle boutique in the Beverly Glen Mall - \u003cb\u003eParis Hilton\u003c/b\u003e: Sydney

more json c# issues

☆樱花仙子☆ 提交于 2019-12-06 08:10:28
This is a continuation of a previous question of mine. The solution worked for what I was trying to do at the time but broke a whole lot of my code. I know it was bad practice not to make sure beforehand but yeah... you live and learn. Anyhoo, here's the Q: an easy way to serialise c# objects What I want to know is: is there any way to get the NewtonSoft Library to handle this stuff? If yes, how? If no, suggestions? What i'm doing is chatting to a RoR3 app using json, now I cant deserialise the response. here's a little code: The response i'm getting from RoR looks like: [{"directory":{

Can I set a custom JsonSerializer to RestSharp RestClient

非 Y 不嫁゛ 提交于 2019-12-06 08:09:18
I'm using the custom JsonSerializer as mentioned in the Readme file in the RestSharp package. Up until now I added the custom serializer to each request: RestRequest request = new RestRequest("scans", Method.POST); request.JsonSerializer = new MyCustomJsonSerializer(); But the read me file mentained I can add it straight to the restclient: There is one breaking change: the default Json Serializer is no longer compatible with Json.NET. To use Json.NET for serialization, copy the code from https://github.com/restsharp/RestSharp/blob/86b31f9adf049d7fb821de8279154f41a17b36f7/RestSharp/Serializers

Newtonsoft.Json.dll issue when using multiple projects

人走茶凉 提交于 2019-12-06 08:01:26
问题 I am seeing some really odd behavior that I have not been able to correct related to references for Newtonsoft.Json.dll. I have a sample solution set up with the following projects: JsonProblem.Core JsonProblem.CauseProblem (references JsonProblem.Core) JsonProblem.Web (references JsonProblem.Core and JsonProblem.CauseProblem) In JsonProblem.Core and JsonProblem.Web I have added the "Microsoft ASP.NET Web API 2.2" NuGet package. In JsonProblem.Core I have created a web api. If I build

Newtonsoft.json serializing and deserializing base/inheirited where classes are from shared projects

假如想象 提交于 2019-12-06 07:56:29
So I have two classes like the ones below. They are both in the same namespace and in the same shared project. public class Person{ public string Name{get;set;} } public class EmployedPerson : Person{ public string JobTitle{get;set;} } When I serilize these items into rabbitmq I am serializing as the base class like so: JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple, TypeNameHandling = TypeNameHandling.Objects }; JsonConvert.SerializeObject(input, settings) However when deserializing I run into issues. I

How to use JSON.Net to read JSON and output HTML?

十年热恋 提交于 2019-12-06 07:43:14
问题 How can I use JSON.Net and loop through the following JSON to output one HTML image tag (a string) for each member of the "photos" object? My goal is to read the below JSON and output this string: "<img src='/images/foo.jpg' alt='Hello World!'><img src='/images/bar.jpg' alt='Another Photo' />" JSON is stored in external file "photos.json" { "photos": { "photo1": { "src": "/images/foo.jpg", "alt": "Hello World!" }, "photo2": { "src": "/images/bar.jpg", "alt": "Another Photo" } } } I've started

Newtonsoft JSON PreserveReferencesHandling with custom Equals usage

落爺英雄遲暮 提交于 2019-12-06 07:32:13
问题 I'm currently having some issues with Newtonsoft Json. What I want is simple: Compare the Object which will be serialized with all Properties and Subproperties for Equality. I tried now to Create my own EqualityComparer but it only compared with the Properties of the Parent Object. Also, I tried to write my own ReferenceResolver but had no luck with it. Let's talk with an Example: public class EntityA { int Foo {get; set;} public override bool Equals(object obj) { return (obj is EntityA other

JSON.NET Deserialization Property Name conversion to ExpandoObject with custom ContractResolver

只愿长相守 提交于 2019-12-06 07:19:52
问题 I have this JSON: {"firstName": "John","lastName": "Doe"} This JSON.NET Contract Resolver: public class CustomContractResolver : DefaultContractResolver{ protected override string ResolvePropertyName(string propertyName) { return propertyName.Replace("_",""); } } And I have this WebApi Controller method with uses an expando to a partial update of a db row using the provided fields: public virtual int Post(int id, JObject content) { var obj = JsonConvert.DeserializeObject<ExpandoObject>