json.net

Reading JSON files with C# and JSON.net

冷暖自知 提交于 2020-01-12 05:45:09
问题 Im having some trouble to understand how to use JSON.net to read a json file. The file is looking like this: "version": { "files": [ { "url": "http://www.url.com/", "name": "someName" }, { "name": "someOtherName" "url": "http://www.url.com/" "clientreq": true }, .... I really do not have much idea how i can read this file .. What i need to do is to read the lines and download the file via the "url".. I know how to download files and so on, but i dont know how i can use JSON.net to read the

create JSON string from SqlDataReader

牧云@^-^@ 提交于 2020-01-12 04:52:12
问题 UPDATE I figured it out. Check out my answer below. I'm trying to create a JSON string representing a row from a database table to return in an HTTP response. It seems like Json.NET would be a good tool to utilize. However, I'm not sure how to do build the JSON string while I'm reading from the database. The problem is marked by the obnoxious comments /******** ********/ // connect to DB theSqlConnection.Open(); // open the connection SqlDataReader reader = sqlCommand.ExecuteReader(); if

How can I parse json string from Httpclient

微笑、不失礼 提交于 2020-01-12 02:49:11
问题 Hi i am getting json result by calling an external api. HttpClient client = new HttpClient(); client.BaseAddress = new Uri(url); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; var s = Newtonsoft.Json.JsonConvert.DeserializeObject(result); return "Success"; } else { return "Fail"; } the

Deserialize JSON into data table in VB.NET using JsonConvert

天大地大妈咪最大 提交于 2020-01-11 13:19:56
问题 I am deserializing JSON into a data table using the below statement in VB.NET. Dim _dt As DataTable = JsonConvert.DeserializeObject(Of DataTable)(myRecords) myRecords is a JSON string. It is working fine, but myRecords has some number properties like {"PhoneNo":"123456789", "ID":"46541"} and after deserialization those properties are converted to a column with data type as string. How can I deserialize them into a number? myRecords is getting dynamically populated, so I can't hard code. 回答1:

Iterate over a json input and create the treeview like hierarchy based on the “keys” taking account of the children “keys”

試著忘記壹切 提交于 2020-01-11 10:38:10
问题 I have the following piece of code: JObject my_obj = JsonConvert.DeserializeObject<JObject>(ReceivedJson); ParseJson(my_obj); //method to store all the nested "keys" and the "id" values public void ParseJson(JObject obj) { foreach (KeyValuePair<string, JToken> sub_obj in (JObject)obj["Soccer"]) { Console.WriteLine(sub_obj.Key); } } //this does not work well as I cant access all the nested keys :/ I am receiving a json in the following format. It could be nested on several levels and I want to

Set accessor not being called when I deserialise object from Json.net

最后都变了- 提交于 2020-01-11 10:29:32
问题 public class SpecialObject { public string ID; [JsonIgnore] public List<SpecialObject> SpecialObjectCollection = new List<SpecialObject>(); [JsonIgnore] public List<string> tempObjectIDs = new List<string>(); [JsonProperty] public List<string> SpecialObjectIDs { get { return SpecialObjectCollection.Select(x => x.ID).ToList(); } set { tempObjectIDs = value; } } public SpecialObject() { } public SpecialObject(string _id) { ID = _id; } } static void Main(string[] args) { SpecialObject parent =

Json.Net How to deserialize null as empty string?

≯℡__Kan透↙ 提交于 2020-01-11 10:07:24
问题 I have string property in my class_ for example [DataMember] [JsonProperty(PropertyName = "email")] [StringLength(40, ErrorMessage = "The Mobile value cannot exceed 40 characters. ")] public string Email { get; set; } By some reason during Convert.Deserialize process I need to have empty string in this property instead on null in case this value is not setup in JSON object. How to do it ? 回答1: You could use the DefaultValue attribute. Decorate it as [DataMember] [JsonProperty(PropertyName =

Json.Net How to deserialize null as empty string?

笑着哭i 提交于 2020-01-11 10:07:15
问题 I have string property in my class_ for example [DataMember] [JsonProperty(PropertyName = "email")] [StringLength(40, ErrorMessage = "The Mobile value cannot exceed 40 characters. ")] public string Email { get; set; } By some reason during Convert.Deserialize process I need to have empty string in this property instead on null in case this value is not setup in JSON object. How to do it ? 回答1: You could use the DefaultValue attribute. Decorate it as [DataMember] [JsonProperty(PropertyName =

Json.NET: Deserilization with Double Quotes

爱⌒轻易说出口 提交于 2020-01-11 05:57:54
问题 I am trying to deserialize a json string received as a response from the service. The client is Windows Phone 7, in C#. I am using Json .NET - James Newton-King deserializor to directly convert the Json string to objects. But sometimes the Json string contains some comments information with double quotes (") in them and the deserializer fails and throws an error. Looks like this is an invalid Json string according to Jsonlint. { "Name": "A1", "Description": "description of the "object" A1" }

Json.NET: Deserilization with Double Quotes

爱⌒轻易说出口 提交于 2020-01-11 05:57:09
问题 I am trying to deserialize a json string received as a response from the service. The client is Windows Phone 7, in C#. I am using Json .NET - James Newton-King deserializor to directly convert the Json string to objects. But sometimes the Json string contains some comments information with double quotes (") in them and the deserializer fails and throws an error. Looks like this is an invalid Json string according to Jsonlint. { "Name": "A1", "Description": "description of the "object" A1" }