json.net

Cannot Json deserialize Youtube data with VB.net

风流意气都作罢 提交于 2019-12-18 09:42:14
问题 I need to obtain the "title" from the response i get from Youtube. I get the following error at line 8, position 12, that is, at line: "items": [ just after the "[" The error i get is: Exception: Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in Newtonsoft.Json.dll ("Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'categoryid.Item' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the

JSON.Net - Use JsonIgnoreAttribute only on serialization (But not when deserialzing)

旧街凉风 提交于 2019-12-18 09:32:02
问题 We're using JSON.net and want to use a consistent way to send and receive data (documents). We want a base class that all documents will be derived from. The base class would have a DocumentType property - This is essentially the class name. When clients post this json-serialized document to the server, we want to deserialize it and ensure the DocumentType specified by the client matches the ExpectedDocumentType on the server. Then as well as this, when this document is serialized by the

JSON to object C# (mapping complex API response to C# object)

回眸只為那壹抹淺笑 提交于 2019-12-18 09:27:37
问题 I am able to handle simple JSON serialization and deserialization but this API response seems little complicated, and I am seeking an advice as to what would be ideal approach to tackle this. I'm trying to call an API for MVC application. Goal is to map API data to model. API endpoint is https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=MyAPIKey Troubles here are: JSON data keys have white space in them. When I tried doing paste special in Visual

Deserialize JSON with varying element names

老子叫甜甜 提交于 2019-12-18 09:14:50
问题 I'm struggling deserializing an json into an vb.net object with newtonsoft. The problem is, that the element name of the following array is different for each array: { "ABC": [{ "key": "123", "md5sum": "e24cb0e730269e419f036a10dd6c38d0", "entity_metadata": { "document_index_end": ["3162"], "document_index_start": ["3147"] } }, { "key": "456", "md5sum": "e24cb0e730269e419f036a10dd6c38d0", "entity_metadata": { "document_index_end": ["3162"], "document_index_start": ["3156"] } } ], "UZT": [{

Can not deserialize JSON containing $ref keys

ⅰ亾dé卋堺 提交于 2019-12-18 09:10:31
问题 I have the following code trying to deserialize a JSON string and the library gives me this error: Additional content found in JSON reference object. A JSON reference object should only have a $ref property. Path 'user.obj', line 1, position 34. Any idea what is wrong? (I understand that it is complaining about the second $ref, but I don't know why.) What is the workaround ? void Main() { var s = "{\"user\": {\"$ref\": \"123456\", \"obj\": {\"$ref\": \"123456\"}}}"; JsonConvert

Why Json.net does not use customized IsoDateTimeConverter?

时间秒杀一切 提交于 2019-12-18 09:09:07
问题 I use Json.net to serialize my objects and I want to customize DateTime output: Here is a small example: [DataContract] class x { [DataMember] [JsonConverter(typeof(IsoDateTimeConverter))] public DateTime datum = new DateTime(1232, 3, 23); } var dtc = new IsoDateTimeConverter(); dtc.DateTimeFormat = "yy"; JsonConvert.SerializeObject(new x(), dtc); The result is {"datum":"1232-03-23T00:00:00"} instead of {"datum":"1232"} . This works correctly (returning "32" ): return JsonConvert

Populate object where objects are reused and arrays are replaced?

ぐ巨炮叔叔 提交于 2019-12-18 09:08:57
问题 Using Json.NET, I'd like to map a JObject onto a .NET object with the following behavior: For (non-null) array properties of the JObject , replace the entire collection on the target object. For (non-null) object properties of the JObject , reuse the target object's property if it's not null, and map just the provided properties onto it. JsonSerializer.Populate seems to be what I want, as described in this answer. As for the behaviors I'm looking for, it seems I can achieve one or the other,

JsonConvert.DeserializeObject and “d” wrapper in WCF

六眼飞鱼酱① 提交于 2019-12-18 09:01:40
问题 By default WCF service wrap JSON response in "d" wrapper and there I found a problem with parsing it. If I parse with JsonConvert.DeserializeObject(response) where response is "{\"d\":\"{\"a0b70d2f-7fe4-4aa2-b600-066201eab82d\":\"Thelma\",\"d56d4d4f-6029-40df-a23b-de27617a1e43\":\"Louise\"}\"}" I gor an Error: After parsing a value an unexpected character was encoutered: a. Line 1, position 9. If I change response into "{\"a0b70d2f-7fe4-4aa2-b600-066201eab82d\":\"Thelma\",\"d56d4d4f-6029-40df

JSON.NET Partial Update Rest API Client

被刻印的时光 ゝ 提交于 2019-12-18 08:56:25
问题 I am building a C#/.NET 4.5 client for a REST API using JSON.NET. The API supports partial updates; therefore the presence or lack of an attribute in the json on an update has meaning. If the attribute is in the json, the server will set the value accordingly; the the attribute is not passed the server will not update it. This also applies to null values. I have .NET classes for each model; with properties for each JSON attribute (pretty standard). As an example lets say I have this account

Strategies for migrating serialized Json.NET document between versions/formats

﹥>﹥吖頭↗ 提交于 2019-12-18 08:50:03
问题 I'm using Json.Net to serialize some application data. Of course, the application specs have slightly changed and we need to refactor some of the business object data. What are some viable strategies to migrate previously serialized data to our new data format? For example, say we have orignally had a business object like: public class Owner { public string Name {get;set;} } public class LeaseInstrument { public ObservableCollection<Owner> OriginalLessees {get;set;} } We serialize an instance