json-deserialization

Unable to deserialize the JSON result in C#. Input string is not in a correct format error

北城以北 提交于 2019-12-23 09:19:40
问题 I am trying to deserialize a json output to a C# object. JSON result: {"order":{"commission":3.490000,"cost":4.490000,"duration":"day","extended_hours ":false,"fees":0.000000,"class":"equity","price":1.000000,"quantity":1.000000,"r equest_date":"2013-11-26T09:43:17.118Z","result":true,"side":"buy","status":"ok" ,"symbol":"DIS","type":"limit"}} My derived class from JSON: public class Rootobject { public Order Order { get; set; } } public class Order { public float commission { get; set; }

PHP json_decode return error code 4

两盒软妹~` 提交于 2019-12-23 08:56:05
问题 I had previously asked the same question. I would like to decode the json from: http://pad.skyozora.com/data/pets.json. Below is the code I used previously: <?php $html=file_get_contents("http://pad.skyozora.com/data/pets.json"); var_dump(json_decode($html,true)); //return null var_dump(json_last_error()); // return 4 ?> From the last answer I know there is UTF8 DOM in the json return. I tried the answer from a similar question: json_decode returns NULL after webservice call, but all of the

Newtonsoft escaped JSON string unable to deseralize to an object

浪子不回头ぞ 提交于 2019-12-23 02:03:04
问题 Question background: I am receiving a JSON response via a HttpResponseMessage, as shown: var jsonString= response.Content.ReadAsStringAsync().Result; This is giving me the following simple escaped JSON string result: "\"{\\\"A\\\":\\\"B\\\"}\"" The problem: I am using Newtonsoft to try and deserialize this to a model: SimpleModel simpleModel= JsonConvert.DeserializeObject<SimpleModel>(jsonString); The Class model of SimpleModel : public class SimpleModel { public string A { set; get; } } The

How to trigger calls to .serializeWithType() of a class implementing JsonSerializable in Jackson?

会有一股神秘感。 提交于 2019-12-22 04:51:18
问题 This is Jackson 2.2.x. I have a class implementing JsonSerializable; there are two methods to implement for this interface, serialize() and serializeWithType() . I want to test {de,}serialization of this class, and I can trigger calls to serialize() easily; not, however, serializeWithType() . The javadoc for this latter method says that this method is called [...] when additional type information is expected to be included in serialization, for deserialization to use. I just don't understand

JSON.Net - cannot deserialize the current json object (e.g. {“name”:“value”}) into type 'system.collections.generic.list`1

泄露秘密 提交于 2019-12-21 12:42:05
问题 I have a JSON like { "40": { "name": "Team A vs Team B", "value": { "home": 1, "away": 0 } }, "45": { "name": "Team A vs Team C", "value": { "home": 2, "away": 0 } }, "50": { "name": "Team A vs Team D", "value": { "home": 0, "away": 2 } } } So it's kind of list of matches. And I have the class to deserialize it into: public class Match { [JsonProperty(PropertyName = "name")] public string Name { get; set; } [JsonProperty(PropertyName = "value")] public Value Values { get; set; } } public

How to iterate a JSONObject (gson)

别等时光非礼了梦想. 提交于 2019-12-21 09:16:32
问题 I have a JsonObject e.g JsonObject jsonObject = {"keyInt":2,"keyString":"val1","id":"0123456"} Every JSONObject contains a "id" entry, but th number of other key/value pairs is NOT determined, so I want to create create an object with 2 attributes: class myGenericObject { Map<String, Object> attributes; String id; } So I want my attributes map to look like this: "keyInt" -> 4711 "keyStr" -> "val1" I found this solution Map<String, Object> attributes = new HashMap<String, Object>(); Set<Entry

CustomDeserializer has no default (no arg) constructor

筅森魡賤 提交于 2019-12-21 03:59:33
问题 I am consuming a REST Api with RestTemplate. The response I'm getting from the API has lots of nested objects. Here's a little snippet as an example: "formularios": [ { "form_data_id": "123006", "form_data": { "form_data_id": "123006", "form_id": "111", "efs": { "1": {}, "2": "{\"t\":\"c\",\"st\":\"m\",\"v\":[{\"id\":\"3675\",\"l\":\"a) Just an example\",\"v\":\"1\"},{\"id\":\"3676\",\"l\":\"b) Another example.\",\"v\":\"2\"}]}" } } The problem I'm having is that most of the times the "1"

Efficient parsing of first four elements of large JSON arrays

旧时模样 提交于 2019-12-20 04:13:09
问题 I am using Jackson to parse JSON from a json inputStream which looks like following: [ [ 36, 100, "The 3n + 1 problem", 56717, 0, 1000000000, 0, 6316, 0, 0, 88834, 0, 45930, 0, 46527, 5209, 200860, 3597, 149256, 3000, 1 ], [ ........ ], [ ........ ], .....// and almost 5000 arrays like above ] This is the original feed link: http://uhunt.felix-halim.net/api/p I want to parse it and keep only the first 4 elements of every array and skip other 18 elements. 36 100 The 3n + 1 problem 56717 Code

Json Deserialization in Java /w Jackson of mixed types, contained in one array

泪湿孤枕 提交于 2019-12-20 02:58:24
问题 Consider the following json, getting from an public API: anyObject : { attributes: [ { "name":"anyName", "value":"anyValue" }, { "name":"anyName", "value": { "key":"anyKey", "label":"anyLabel" } } ] } As you can see, sometimes the value is a simple string and sometimes its an object. Is it somehow possible to deserialize those kind of json-results, to something like: class AnyObject { List<Attribute> attributes; } class Attribute { private String key; private String label; } How would I

Best way to denote time (without date) in Swagger spec

匆匆过客 提交于 2019-12-19 10:17:17
问题 What is the best way to represent a time field in a swagger specification, the closest type to denote it looks like date-time but this makes standard deserialisers to expect date field to be passed along with the time... Is there a standard or best practice to just denote time in a swagger spec that works well with the Jackson deserialisers? Is denoting time in milliseconds/seconds and using type string in swagger an acceptable approach? 回答1: Depending on what you're trying to represent, this