json.net

Invalid format with Json when converting DataTable with Json.Net

末鹿安然 提交于 2019-12-11 13:19:55
问题 I'm trying to convert DataTable to JSON using Newtonsoft.JSON but found that the output is not what ExtJS grid and chart would expect. My code is string output = JsonConvert.SerializeObject(dt, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); and this returns Json string as "[{\"DAYDATE\":\"2012-05-22T00:15:00\",\"SERIES1\":3.65}]" If I remove '\' and start and end double quotes it works fine with ExtJS. I also tried changing date

Deserialize Json encountered URL change

只谈情不闲聊 提交于 2019-12-11 13:19:23
问题 I have an Json string return by facebook api and I want to cast it to an object, I tried using both Newton Json and JavaScriptSerializer. https://graph.facebook.com/v1.0/1111111111111/comments?limit=25&after=NTA\u00253D After I cast it to a strongly typed object or a dynamic object, the url will be changed to https://graph.facebook.com/v1.0/1111111111111/comments?limit=25&after=NTA%3D What is the cause of this issue? I have tried url encoding and decoding, but it didn't work. 回答1: In JSON,

LINQ to Json data retrieval from polymorphic json

喜欢而已 提交于 2019-12-11 12:52:28
问题 I have a polymorphic json string. Here's what it looks like: { "?xml":{ "@version":"1.0", "@encoding":"UTF-8" }, "DataFeed":{ "@FeedName":"AdminData", "Issuer":[ { "name":"Apple", "symbol":"AAPL-O", "active":"1", "securities":{ "Security":{ "sedol":"B0XXF09", "coverage":{ "Coverage":{ "analyst":{ "@firstName":"Steve", "@lastName":"Jobs", "@rank":"1" } } }, "symbolMappingList":{ "SecuritySymbol":{ "symbolset":{ "id":"11", "symbol":"ISIN", "name":"ISIN", "rixmlName":"ISIN", "researchDirect":"S

JSON.Net throwing System.Security.VerificationException: Operation could destabilize the runtime

爷,独闯天下 提交于 2019-12-11 12:51:19
问题 I have a web application which uses JSON.Net to write out an array of data from a .Net Array(). When run in the VS2010 environment, it works fine. When run under IIS6 and .Net 3.5, it works fine. When run under IIS7 or 7.5 and .Net 3.5 when .Net 4.0 is installed (but the app pool and site is set to use v2 runtime), it fails with the exception 'System.Security.VerificationException: Operation could destabilize the runtime.' I do not have access to an IIS7 (or 7.5) system without .Net 4.,0 so I

Deserialize json with Json.NET

烂漫一生 提交于 2019-12-11 12:48:39
问题 I have JSON that looks like this (from the Philips HUE API): { "1": {"name": "Bedroom"}, "2": {"name": "Kitchen"} } When I try to deserialize this document I run into problems because the document is structured the way it is. If it had been formated like this: [ {"nr": "1", "name": "Bedroom"}, {"nr": "2", "name": "Kitchen"} ] Everything would have been fine. Now I am forced to do string parsing in order to extract the data... :-( Any ideas or suggestions? 回答1: I would deserialize to JObject

Add name value pairs to a JObject within a JArray

青春壹個敷衍的年華 提交于 2019-12-11 12:48:20
问题 { "x": null, "y": null, "z": null, "things": [ { "x": 1, "y": 1 }, { "x": 1, "y": 6 } ] } I want to push another pair into things[0] so that it reads "things": [ { "x": 1, "y": 1, "z": 9000 }, I can easily modify the values like this: JObject myobject = JObject.Parse(responseString); JArray myarray = (JArray)myobject["things"]; myarray[0]["x"] = 9000; I can't figure out how to add/append to this object instead. It appears myarray[0] is a JToken , even though it is an object when I do GetType(

How do I parse Json with an invalid character for a field name? e.g. { “file/folder”: “/Shared/Salesforce/asdf.txt” } with Newtonsoft?

独自空忆成欢 提交于 2019-12-11 12:22:42
问题 I received the following JSON from a webservice. How do I parse the following JSON in Netwtonsoft? { "file/folder": "/Shared/Salesforce/asdf.txt" } ^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^---that is my problem Note that the field name has a forward slash, which is invalid for C# when used as a field name. (Newtownsoft does automatic mappings between JSON names and C# fields) The code I have is JsonSerializerSettings set = new JsonSerializerSettings(); List<UserAudit> usrs = JsonConvert

Deserialize JSON with dynamic key into Object

久未见 提交于 2019-12-11 12:06:13
问题 I know there have been some questions already raised about this topic however I still struggle o understand it. I have quite a complex JSON object returning which has a dynamic key at the beginning. I am trying to deserialize it into a C# object model but my problem is the dynamic key: { "ISBN:0903393972": { "bib_key": "ISBN:0903393972", "details": { "publishers": ["Sweet & Maxwell"], "physical_format": "Hardcover", "title": "Tanker Voyage Charter Parties", "created": { "type": "/type

JSON serializer adding extra character as '\'in response while serializing custom datatype in custom JsonConverter

对着背影说爱祢 提交于 2019-12-11 12:03:19
问题 I am using custom JsonConverter(CustomInfoConverter ) to do some manipulation in each of my custom dot net type(CustomType) which is getting parse. Below is the code for custom JsonConverter: public class CustomInfoConverter : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(CustomType); } public override bool CanRead { get { return false; } } public override bool CanWrite { get { return true; } } public override void WriteJson(JsonWriter writer,

How to force json.net to deserialize DataTable column from integer to float

二次信任 提交于 2019-12-11 11:59:58
问题 I am trying to desrialize a json into a datatable. My JSON looks like below: [{ "Id": 35, "Name": "ABC", "XVar": 0.078814, "YVar": 1 }, { "Id": 79, "Name": "XYZ", "XVar": 1.50, "YVar": 30.2 }] I'm using the following code to deserialize: var dataTable = (DataTable)JsonConvert.DeserializeObject(jsonString, (typeof(DataTable))); The problem is that the Y value for the second object is serialized as 30 and not 30.2. What is the simplest thing I can do to preserve the data. All ideas are welcome.