json.net

Parse JSON query in C#

心不动则不痛 提交于 2019-12-25 03:07:50
问题 I want to develop an website in C# that parses data from a JSON query in order to use them later. So far I have found all the libraries to use, but after many attempts parsing does not work and I would like your help please. I use visual studio 2010 professional. Here is the C# code. using System; using System.Collections.Generic; using System.Net; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net.Json; using System.Text; using Newtonsoft.Json.Linq;

Convert JSon to dynamic object in VB.Net

为君一笑 提交于 2019-12-25 03:06:26
问题 I am using VB.Net and calling salesforce API. It returns very ugly JSON which I am not able to deserialize. I have a following code using JSON.Net Dim objDescription As Object = JsonConvert.DeserializeObject(Of Object)(result) objDescription contains many properties, one on=f them in fields . But when I write something like objDescription.fields it gives me error. objDescription.fields Public member 'fields' on type 'JObject' not found. Object I am not very sure but I think it C# allow to

ajax request that returns json array, IE6/7 is caching it and data is not fresh

天大地大妈咪最大 提交于 2019-12-25 02:47:35
问题 for some reason, IE6/7 is caching the ajax call that returns a json result set back. My page makes the call, and returns a json result which I then inject into the page. How can I force IE6/7 to make this call and not use a cached return value? 回答1: You might want to add Cache-Control: no-cache to your HTML response headers when you're serving the JSON to tell the browser to not to cache the response. In ASP.NET (or ASP.NET MVC) you can do it like this: Response.Headers.Add("Cache-Control",

Deserialize Json Using Json.net

≡放荡痞女 提交于 2019-12-25 02:38:29
问题 parse this Json and Get The Values Usign Json.NET.Help Me to Find The Way To Parse. Thanks in Advance.. I am Using Json.net Dll For Parsing,Below is my Json Code and C# code to Parse, But I am Getting Error, Confuced to Get the Values From This Json File. myjson.json: { "Published_DocsCount": 5, "Public_ReadAccess": 2, "Public_CommentAccess": 3, "Public_WriteAccess": 2, "Public_DocsCount": 7, "PublicWithLink_ReadAccess": 2, "PublicWithLink_CommentAccess": 2, "PublicWithLink_WriteAccess": 2,

Converting an object to json in specified format-contd

偶尔善良 提交于 2019-12-25 02:26:51
问题 This question is a continuation of this.., rather than changing it, I'm asking a new one here.. My required json format is { "nodes": { "1": { "2": { "attriba": "a2", "label": "2", "attribc": false }, "3": { "attriba": "a3", "label": "3", "attribc": false } }, "6": { "4": { "attriba": "none", "label": "4", "attribc": false }, "5": { "attriba": "none", "label": "5", "attribc": false } } } } Now normally I would create classes and fill them with data and call "Newtonsoft.Json.JsonConvert

How to serialize a string-valued property as a string array

别说谁变了你拦得住时间么 提交于 2019-12-25 01:49:24
问题 I have a class: Public Class ExtraInfo Property extratypes As String End Class I have a form submitted and the value assign is string, the data submitted from form is string not array: extratypes = '1,2'; Now when I save into the database as json: Newtonsoft.Json.JsonConvert.SerializeObject(edited) it give me this in json: {"extratypes":"1,2"} How can I manipulate it to string array before saving it like the one below: {"extratypes":["1","2"]} 回答1: Use an array in your model: Public Class

Serialize list of objects with JSON.NET in C#

不羁的心 提交于 2019-12-25 01:45:47
问题 I have a List that looks like: List<Product> products = new List<Product>(); Product p1 = new Product(1, "Apple", new Description("Red Apple")) Product p2 = new Product(2, "Banana", new Description("Yellow Banana")) products.Add(p1); products.Add(p2); A product looks like this: //Product model public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual Description descriptions { get; set; } //Description model public string description { get; set } Now I want

Parsing JSON list to int array in c#

我们两清 提交于 2019-12-25 00:55:03
问题 I'm having trouble reading a JSON list of numbers into a c# int[] array. I've tried several suggestions from SO, but none have worked. How would I go about this using JSON.net? Extract from JSON file: { "course": "Norsk", "grades": [6, 3, 5, 6, 2, 8] } What I've tried in c#: // Reads the JSON file into a single string string json = File.ReadAllText(jfile); Console.WriteLine(json); // Parsing the information to a format json.net can work with JObject data = JObject.Parse(json); JToken jToken =

JSon.Net Json to entity

旧时模样 提交于 2019-12-25 00:47:12
问题 I have an entity, I setup the entity with the database you see below as an edmx file. I also have a JSon file that I am pulling from edmunds.com I am using JSon.net and trying to parse the JSon object into the Entity and save the values of the Json to the Entity. Every option I try to use it seems to blow up on me. Can anyone please provide me a decent example of how to accomplish this as it is driving me insane at this point. { "dealerHolder":[ { "id":"31711", "locationId":"3730", "address":

Convert Rest API JSON Response into C# object

浪子不回头ぞ 提交于 2019-12-24 23:24:23
问题 I have a code REST API response which is json, and parsing to JObject and pulling a value from it. But i am getting the error when parsing to JObject. Error: "Unexpected character encountered while parsing value: S. Path '', line 0, position 0." Is there any other way to convert Json string to C# object. I have the following code: using Newtonsoft.Json; using (HttpResponseMessage message = httpclient.GetAsync(folderIdURL).Result) { if(message.IsSuccessStatusCode) { var dataobjects = message