javascriptserializer

Deserialize nested JSON array in C#

∥☆過路亽.° 提交于 2019-12-02 04:10:51
问题 I have a JSON array with nested objects, representing a menu, as this: [ [ { "name": "Item 1", "id": 1 }, { "name": "Item 2", "id": 2, "children": [ [ { "name": "Item 21", "id": 21 } ] ] }, { "name": "Item 3", "id": 3, "children": [ [ { "name": "Item 31", "id": 31, "children": [ [ { "name": "Item 311", "id": 311 }, { "name": "Item 312", "id": 312 } ] ] }, { "name": "Item 32", "id": 32 }, ... And I want to deserialize it using JavaScriptSerializer. I have some code as shown below but is not

How do I use JavaScriptSerializer in ASP.NET 5?

前提是你 提交于 2019-12-02 00:57:02
问题 I am porting my project to DNX-Core 5.0 and trying to get work but I cannot find the JavaScriptSerializer and AppSettingReader classes. I know the System.Web is removed and so please anyone help me to find the alternative of using them. Is there any Nuget available to include them? 回答1: The ASP.Net 5 team dropped the JavaScriptSerializer in favor of the widely used Newtonsoft.Json package, but they did provide a JsonOutputFormatter and a JsonInputFormatter for use with MVC to be able to

Deserialize nested JSON array in C#

别说谁变了你拦得住时间么 提交于 2019-12-01 23:46:25
I have a JSON array with nested objects, representing a menu, as this: [ [ { "name": "Item 1", "id": 1 }, { "name": "Item 2", "id": 2, "children": [ [ { "name": "Item 21", "id": 21 } ] ] }, { "name": "Item 3", "id": 3, "children": [ [ { "name": "Item 31", "id": 31, "children": [ [ { "name": "Item 311", "id": 311 }, { "name": "Item 312", "id": 312 } ] ] }, { "name": "Item 32", "id": 32 }, ... And I want to deserialize it using JavaScriptSerializer. I have some code as shown below but is not working. var serializer = new JavaScriptSerializer(); var objects = serializer.Deserialize<Menu>(jsonData

JSON deserialize to class with missing key in json [string could be a single string or list string]

二次信任 提交于 2019-12-01 20:42:28
I have below class [Serializable] public class filters { public List<string> key1 { get; set; } public List<string> key2 { get; set; } public List<string> key3 { get; set; } } and json string is [{"key1": "key1value"}] deserializing like filters objFilter = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<filters>(json); json string may contain key1, key2 and key3 or may not. key1, key2, key3 may be a single string or array So how can i deserialize it. It is throwing an error mostly. class is not supported for deserialization of an array Please advise Thanks The problem

How do you serialize an enum array to a Json array of strings? [duplicate]

百般思念 提交于 2019-12-01 18:47:29
This question already has an answer here: Serialize a container of enums as strings using JSON.net 2 answers Based on Diego's unanswered comment under the top-voted answer in this question: JSON serialization of enum as string So for an enum: public enum ContactType { Phone = 0, Email = 1, Mobile = 2 } And for eg. a property: //could contain ContactType.Phone, ContactType.Email, ContactType.Mobile IEnumerable<ContactType> AvailableContactTypes {get;set;} To something like the JSON: {ContactTypes : ['Phone','Email','Mobile']} instead of {ContactTypes : [0,1,2]} As is the case with the normal

JavaScriptSerializer namespace issue

℡╲_俬逩灬. 提交于 2019-12-01 15:09:35
I am having a problem trying to implement the JavaScriptSerializer to parse a JSON string received from a server. I implemented the following code: responseFromServer = readStream.ReadLine(); JavaScriptSerializer ser = new JavaScriptSerializer(); var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(responseFromServer); var status = dict["notificationType"]; Debug.WriteLine(status); I added using System.Web.Script.Serialization; Visual C# 2010 Express is telling me the namespace name Script does not exist in the namespace System.Web . As a result the

How can I do System.Web.Script.Serialization in C#?

亡梦爱人 提交于 2019-12-01 15:05:00
How can I do this in C# modern UI ? var url = "http://ajax.googleapis.com/ajax/services/feed/load?q=http%3A%2F%2Fwww.digg.com%2Frss%2Findex.xml&v=1.0"; var wc = new WebClient(); var rawFeedData = wc.DownloadString(url); //You can use System.Web.Script.Serialization if you don't want to use Json.NET JavaScriptSerializer ser = new JavaScriptSerializer(); FeedApiResult foo = ser.Deserialize<FeedApiResult>(rawFeedData); //Json.NET also return you the same strong typed object var apiResult = JsonConvert.DeserializeObject<FeedApiResult>(rawFeedData); It gives me error an error in WebClient and

How to serialize a raw json field?

拜拜、爱过 提交于 2019-12-01 14:29:08
问题 I have a field in the db that store a json string and I want that when I return it in a json result that will be returned as json raw data and not warped with quotes as string. UPDATE 1(More Info): if you looking at the images field it contain a raw json string value but after serialize it with the JsonResult it get warped with quotes that it ok because is a type of String, how can i tell the serializer to treat the images field as a raw json data? var db = new ModelsContainer(); var res = db

JavaScriptSerializer namespace issue

久未见 提交于 2019-12-01 14:00:25
问题 I am having a problem trying to implement the JavaScriptSerializer to parse a JSON string received from a server. I implemented the following code: responseFromServer = readStream.ReadLine(); JavaScriptSerializer ser = new JavaScriptSerializer(); var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(responseFromServer); var status = dict["notificationType"]; Debug.WriteLine(status); I added using System.Web.Script.Serialization; Visual C# 2010 Express is telling me the

How can I do System.Web.Script.Serialization in C#?

≯℡__Kan透↙ 提交于 2019-12-01 13:56:51
问题 How can I do this in C# modern UI ? var url = "http://ajax.googleapis.com/ajax/services/feed/load?q=http%3A%2F%2Fwww.digg.com%2Frss%2Findex.xml&v=1.0"; var wc = new WebClient(); var rawFeedData = wc.DownloadString(url); //You can use System.Web.Script.Serialization if you don't want to use Json.NET JavaScriptSerializer ser = new JavaScriptSerializer(); FeedApiResult foo = ser.Deserialize<FeedApiResult>(rawFeedData); //Json.NET also return you the same strong typed object var apiResult =