json.net

dynamically change the json property name and serialize

情到浓时终转凉″ 提交于 2019-12-12 05:28:53
问题 i want to change the json property name dynamically and serialize the object. here is my json for two different entities For customer { "userName": "66666", "password": "test1234", "customersList": [ { "address": "Test Stree2", "customerNumber": "US01-000281", "city": "" } ] } For contact { "userName": "66666", "password": "test1234", "contactList": [ { "address": "Test stree1", "contactNumber": "US01-000281", "city": "" } ] } and the model that is holding this data is as follows public class

MVC serialize json using Json.NET

自作多情 提交于 2019-12-12 05:15:14
问题 I have this code inside a Controller [HttpPost] public ActionResult Index([DataSourceRequest]DataSourceRequest request) { var tickets = db.Tickets.Include(t => t.AreaOfBusiness).Include(t => t.Assignee).Include(t => t.Severity).Include(t => t.TicketStatu); return this.Json(tickets.ToDataSourceResult(request)); } but I get A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.Ticket_2B104FE45830306408DA130C08090F61ADA6B8A0106592FECE85087B94B

Complex linq: Nested where statements JSON.net and linq

蹲街弑〆低调 提交于 2019-12-12 05:00:05
问题 What I'm trying to accomplish is to select the dateTimeStart inside the ttSheduleDay. The JSON beneath is a node of one employee, the function receives three parameters an empUID, a date and a value of (start / stop or duration). The node I want to select is where the dsShedule > ttEmployee > empUID equals the first parameter, where the ttShedule > ttSheduleDay > dat equals the date parameter and the third parameter I will execute with an if statement. Below the JSON JSON { "dsShedule": {

I want to query a json file to find users with two or more tags in common

萝らか妹 提交于 2019-12-12 04:38:25
问题 I have the following json file: { "users": [ { "tags": [ "c++", "jquery", "css", "html" ], "name": "John Doe", "id": 0 }, { "tags": [ "vb", "css" ], "name": "Bill Gates", "id": 1 }, { "tags": [ "c++", "css", "html" ], "name": "Steve Jobs", "id": 3 } ] } I'm trying to return only users who match Tags twice or more, for instance: John Doe and Steve Jobs have c++ and css in common. I was trying to achieve this by performing tons of for statements but I don't think this is the best solution. That

Using json.net from string to datatable in C#

懵懂的女人 提交于 2019-12-12 03:59:30
问题 Hopefully can someone help me with an example, because I'm new in JSON: From a webservice I receive a JSON string. I understand it is created from a datatable. How do I manage in C# to Deserialize this to a dataset? Maybe someone has something for me. { "DataToJohnson": { "0": { "maat_id": "1", "maat": "11" }, "1": { "maat_id": "2", "maat": "11+" }, "2": { "maat_id": "3", "maat": "12+" }, "3": { "maat_id": "4", "maat": "12/13" } } } Thanks! Raymond 回答1: You could define a model that will

Deserialize JSon Object error

扶醉桌前 提交于 2019-12-12 03:58:50
问题 Hi I need your help for Deserialize Json Object. This is The code I wrote, String s = File.ReadAllText(@"C:\Users\User\Desktop/json1.json"); var myfields = Newtonsoft.Json.JsonConvert.DeserializeObject<YourTwoField>(s); Console.WriteLine(myfields.FieldOne); and this is the class for the JSON OBJECT using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using System.IO; public class YourTwoField { [JsonProperty

Get a specific value from a json structure

99封情书 提交于 2019-12-12 03:58:28
问题 I have this json: { "unashamedohio": { "id": 107537, "name": "UnashamedOhio", "profileIconId": 785, "revisionDate": 1439997758000, "summonerLevel": 30 } } I want to get the field named summonerLevel . I have tried to convert this json to a string and then search for summonerLevel , but I know that this solution is not okay. I'm using Json.NET. 回答1: You can use the dynamic keyword dynamic obj = JsonConvert.DeserializeObject(json); Console.WriteLine(obj.unashamedohio.summonerLevel); 回答2: I'm

Consuming Api in Console Application

99封情书 提交于 2019-12-12 03:56:50
问题 I'm trying to consume my api using a console application and I'm getting an exception. When I'm trying to put my JSON data to my model, these are the following exceptions: Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in mscorlib.dll Exception thrown: 'System.AggregateException' in mscorlib.dll Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in ConsoleApplication1.exe My Source Code: class Program { public class IndividualModel { public string PayorCode { get;

How do I combine two arrays from two JObjects in Newtonsoft JSON.Net?

若如初见. 提交于 2019-12-12 03:56:30
问题 I have two similar JSON objects that I have run JObject.FromObject() on. In each object there is a property with an array of other objects, like so: Doc1 { "Title": "Alpha", "data": [ { "Id": "Fox2", "Field": "King6", "Value": "Alpha", "Description": "Tango" } ] } Doc2 { "Title": "Bravo", "data": [ { "Id": "Kilo", "Field": "Echo", "Value": "Romeo", "Description": "Jester" } ] } I have two of these objects, and am trying to add the data field from one into the other - basically add the data

Newtonsoft.Json, How to code generic selection

旧城冷巷雨未停 提交于 2019-12-12 03:45:29
问题 Further on with Newtonsoft.Json, Path returned multiple tokens, For this code: JObject o = JObject.Parse(jsStr); IEnumerable<JToken> selEnum = o.SelectTokens(theFilter); where the jsStr is the content of https://api.github.com/search/repositories?q=Newtonsoft.Json&sort=stars&order=desc, and theFilter can be any valid JPATH query string (e.g., ".items" or ".items[*].owner" ). How to return the selected as a valid json string? 回答1: It sounds like you just need Json.SerializeObject : var o =