java,json,jackson,json-deserialization
This kind of structure can be parsed using a custom deserializer added with the JsonDeserialize annotation. POJOs public static class Container { private List<Group> groups; public List<Group> getGroups() { return groups; } public void setGroups(List<Group> groups) { this.groups = groups; } @Override public String toString() { return String.format("Container [groups=%s]", groups);...
c#,string,serialization,json.net,json-deserialization
Part of the issue looks to be the use of double quotes which can be escaped with a backslash \, however to have a multi-line string in C#, you also need to append an @ symbol at the start like shown in this answer http://stackoverflow.com/a/1100265/2603735
java,jackson,json-deserialization
I submitted a finding on github. Tatu from FasterXML looked into it and fixed the issue. Problem was serialization of Class<?> keys in map. It should be fixed in jackson-databind version 2.5.1...
c#,asp.net,json,json-deserialization
Specify the property name in the Name property of a DataMember attribute, or the PropertyName property of a JsonProperty attribute: [DataContract] public class Image { [DataMember(Name="#text")] public string Text { get; set; } [DataMember] public string size { get; set; } } Or public class Image { [JsonProperty("#text")] public string...
java,gson,json-deserialization
Create a class called embedded and add it as a field in Book: public class Book { String name; int published; Embedded embedded; } Then create an embedded class: public class Embedded { Author Author; Publisher Publisher; } Just model your classes after your JSON...
It is giving you that error because outboundOptions is an array of objects. What you want is to access the first object: foreach ($json2['outboundOptions'][0]['flights']as $theentity) { $result[] = $theentity['flightNumber']; } Also, remove the trailing comma (,) from your ] at the end as that causes invalid json. You can check...
java,json,deserialization,json-deserialization,parameterized-types
2.PlacesMainModel contains List geometry; Geometry is not JSONArray so you can't take it as list its a simple nested json object. Make another model for Geometry and use it i place of List Geometry....
c#,json,json.net,json-deserialization
In this case, you should ask Deserializer for IDictionary<string, Match> var mList= JsonConvert.DeserializeObject<IDictionary<string, Match>(jsonstr); And the first element would have key "40" and the value will be the Match instance Other words this part: "40": { "name": "Team A vs Team B", "value": { "home": 1, "away": 0 } will...
json,vb.net,servicestack,json-deserialization,servicestack-text
Based on the returned JSON of: {"complaints":[{"feedback_type":"abuse","subject":"Sales Agent Position"},{"feedback_type":"abuse","subject":"Sales Agent Position"}],"message":"OK","code":0} You will need two DTOs to deserialise this result. I have used auto implemented properties here to simplify the complexity of the code. If you use an older version of VB, you'll need to expand these out to include...
java,android,json,jackson,json-deserialization
What I did here was creating my own deserializer and using it when creating the Gson: Gson gson = new GsonBuilder().registerTypeAdapter(MyModel.class, new MyJsonDeserializer()) .create(); And here's the deserializer: public class MyJsonDeserializer implements JsonDeserializer<MyModel> { @Override public MyModel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Gson gson = new...
java,json,jackson,deserialization,json-deserialization
Create an ObjectReader to configure the root name explicitly: @Test public void testUnwrapping() throws IOException { String json = "{\"customers\":[{\"email\":\"[email protected]\"},{\"email\":\"[email protected]\"}]}"; ObjectReader objectReader = mapper.reader(new TypeReference<List<Customer>>() {}) .withRootName("customers"); List<Customer> customers = objectReader.readValue(json); assertThat(customers, contains(customer("[email protected]"), customer("[email protected]"))); } (btw this is with Jackson 2.5, do you...
gson,deserialization,json-deserialization
Changing the return type of deserialize() from Category to ArrayList<Category> solved the issue. Rest of the code is correct.
c#,json,json.net,deserialization,json-deserialization
Ok figured out how it will work! Object tree has to be: public class Payload { [JsonProperty("solarforecast")] public Dictionary<int, Dictionary<DateTime, SolarForecastTimeSet>> SolarForecast; } public class SolarForecastTimeSet { [JsonProperty("dh")] public decimal DiffusRadiationHorizontal; [JsonProperty("bh")] public decimal DirectRadiationHorizontal; } Thanks @andyp for his dictionary hint!...
c#,json,json.net,json-deserialization
As soon as the classes got auto-generated by the website I mentioned, I noticed it wasn't safe to have certain fields typed as int and others as double (specially regarding the Stats class), because what is int now may not be int in some other case. So I changed them...
c#,serialization,json.net,json-deserialization,httpcookiecollection
JSON.NET doesn't support deserializing non-generic IEnumerables. CookieCollection implements IEnumerable and ICollection, but not IEnumerable<Cookie>. When JSON.NET goes to deserialize the collection, it doesn't know what to deserialize the individual items in the IEnumerable into. Contrast this with IList<Cookie> which has a generic type parameter. JSON.NET can determine what type each...
c#,.net,deserialization,json-deserialization
You can't do that. You can check if object is serializable with typeof(T).IsSerializable. What you can do is wrap this in try-catch block and then do operation on object if serialization succeds. JavaScriptSerializer().DeserializeObject() usually always succeds but the casting then does not where JavaScriptSerializer().DeserializeObject() throws an exception if input includes...
asp.net-web-api,json-deserialization
You can solve this issue by appending a comma. Neat</sarcasm>. { ParentId: 2, ChildId: 333333333333333333333333333333333333333, } So it does indeed look like a deserializer bug as noted by @djikay in the comments above. Update: The issue has been fixed: https://github.com/JamesNK/Newtonsoft.Json/issues/315...
java,json,deserialization,gson,json-deserialization
ob.contents_array = gson.fromJson(ob.file_contents, ArrayList.class); Instead of a raw ArrayList.class you should use a TypeToken to tell Gson the actual runtime type of the ArrayList's type parameter: ob.contents_array = gson.fromJson(ob.file_contents, new TypeToken<ArrayList<tweet>>(){}.getType()); ...
.net,json,vb.net,deserialization,json-deserialization
I would suggest using JSON.NET instead of the DataContractJsonSerializer (even though it probably could do the job)
ajax,arrays,asp.net-mvc,json,json-deserialization
Your JSON has a top level property called "Submission" that your .NET Object does not. That is going to keep it from parsing into the object correctly, though I cannot say with 100% certainty that that is the reason why. based on your edit, here is my edit: self.submitOrder =...
c#,json,json.net,json-deserialization
Make a custom Key class: public class Key { public int Base { get; set; } public int Max { get; set; } } Then store each item in the JSON result in a Dictionary where it's key is the key name and it's value is a Key item: var...
java,android,json,gson,json-deserialization
Your problem is here: String data = dataElem.getAsJsonObject().get("data").getAsString(); You don't want a String, you want the actual JsonElement from the parse tree: JsonElement je = dataElem.getAsJsonObject().get("data"); Then your deserialization to an array of your Model will work: bundle.putParcelableArray("models", gson.fromJson(je, Model[].class)); ...
c#,json,datetime,json-deserialization,jsonserializer
since in my case I don't really care about time and the timezone is always in EDT, i wrote this to get around this issue in the short term. private DateTime? ParseMe(string s) { var split = s.Split(new[] {' '},StringSplitOptions.RemoveEmptyEntries); var year = int.Parse(split[split.Count()-1]); var day = int.Parse(split[2]); var month...
javascript,asp.net-mvc,deserialization,json-deserialization
You need to create a wrapper class to deserialize properly: [Serializable] public class DecryptedMonthlyPremiumScale { [DataMember] public int PlId { get; set; } [DataMember] public int PstId { get; set; } [DataMember] public string MonthlyValue { get; set; } } public class Root { public IList<DecryptedMonthlyPremiumScale> list {get;set;} } var...
c#,json.net,json-deserialization
Based on your loop below foreach (var json in output) { jObt ob = JsonConvert.DeserializeObject<jObt>(json); usr.Insert_Schedule(ob.empid, ob.status); } You're calling usr.Insert_Schedule method more than once if the json contains multiple objects. Now let's have a look at the definition of usr.Insert_Schedule method below public void Insert_Schedule(string empid, string status) {...
c#,json,windows-phone-8,json.net,json-deserialization
You just need to bind the current element. So just edit the image binding as follows: <Image Source="{Binding}" Height="219" Width="153" /> ...
java,jackson,json-deserialization,fasterxml
Use Map<Integer, String> map2 = mapper.readValue(json, new TypeReference<Map<Integer, String>>(){}); or Map<Integer, String> map2 = mapper.readValue(json, TypeFactory.defaultInstance() .constructMapType(HashMap.class, Integer.class, String.class)); Your program will output below text: deserialize 1 deserialize 2 {1=foo, 2=bar} class java.lang.Integer ...
javascript,jquery,ajax,json,json-deserialization
Assuming that you set the datatype parameter to json (or leave it at the default setting and it recognises the JSON format by itself) then jQuery will automatically deserialise the response for you. The error you see is normally an indication that you are trying to parse twice. Try this:...
c#,servicestack,json-deserialization
Support for the condensed yyyyMMdd date format was just added so ServiceStack's Json Serializer can now handle dates like 20001213, e.g: var date = "20001213".FromJson<DateTime>(); // new DateTime(2000, 12, 13) There's also a new DateTimeSerializer.OnParseErrorFn where you can handle invalid date formats, e.g: DateTimeSerializer.OnParseErrorFn = (str, ex) => DateTime.ParseExact(str, "yyMMdd",...
c#,json,class,json-deserialization
First, I'd contact the owner of the webservice and tell them they're serving invalid JSON. The outer {...} that's there currently means that they're serving an Object, but that object has no keys and values (which are required), it just wraps an Array. Anyway, you could get around this by...
javascript,json,serialization,json-deserialization
You could nest an array in this part, like so: Without minimax: { "HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68", "DateTime": "2014-05-13T09:24:49", "ChannelsValues": [ [0.449212707644754], [1.11111], [1.452433] ] }, With minimax: { "HistoryId": "bf39d7cfca8536b3e00e5355dff25a97715bc439a5c73d41d10a9eb0c45f2e68", "DateTime": "2014-05-13T09:24:49", "ChannelsValues": [ [0.449212707644754], [1.11111, 1.63245345], [1.452433] ] }, Then on parsing, you would only have to check how many...
json,libgdx,json-deserialization
I was looking for the same thing, finally this implemented read method worked for me, I hope it works for you too: @Override public void read(Json json, JsonValue jsonMap) { json.readFields(this, jsonMap); } ...
c#,servicestack,json-deserialization
Your LoginResultModel class does not contain any public properties. So there is nothing to serialise, and you will then have an empty result. What you have done is created other classes within the LoginResultModel which I believe you meant to implement as properties. What you should really do is create...
java,android,json,gson,json-deserialization
change private List<class2> vals; to private List<class2> subvalues
java,json,generics,gson,json-deserialization
First, don't use raw types. Second, You'll need to use type tokens. A TypeToken is a pseudo-hack to get around some of the limitations of type erasure. You'll need to create a type token TypeToken token = new TypeToken<ResponseDate<LocationData>>() {}; And then feed the TypeToken's represented type to Gson (don't...
When the json allows for games without the dire_team and/or radiant_team property, you should do null checks to make sure they are there: foreach (var leagues in liveGames.Result.games){ if(leagues.dire_team != null) MessageBox.Show(leagues.dire_team.team_id.ToString()); else MessageBox.Show("no dire team for this game"); if(leagues.radiant_team != null) MessageBox.Show(leagues.radiant_team.team_id.ToString()); else MessageBox.Show("no radiant team for this game");...
c#,json,json.net,json-deserialization
If I understood correctly you have a problem initializing the Guid on deserialization and you don't want to create a setter or use attributes for successful deserialization. Please note that I changed your MyIdentity class by removing the constructor that accepted Guid parameter since it's not necessary, changed the parsing...
The easiest way to do this would be to add a get-only property for the parent id (private or public as you prefer), and serialize that, ignoring the actual Parent property: public class Category { public int id; public string name; [JsonIgnore] public Category Parent; [JsonProperty("parent", NullValueHandling = NullValueHandling.Ignore)] int?...
c#,json,json.net,arrays,json-deserialization
Since current_call is sometimes an object, sometimes an array and sometimes not there at all, you will need to use a JsonConverter in order to avoid errors. You can use the SingleOrArrayConverter<T> converter from this similar question and combine it with a null check to get a workable solution. Here...
c#,wcf,datetime,serialization,json-deserialization
I am using Newtonsoft to serialize the date format to hold ISODate format. I was able to solve my problem doing this: Test.cs: [DataContract] public class Test { public DateTime xaaaaaa { get; set; } [DataMember(Name = "xaaaaaa")] private string HiredForSerialization { get; set; } [OnSerializing] void OnSerializing(StreamingContext ctx) {...
c#,json,json.net,deserialization,json-deserialization
First of all, your JSON is not properly formatted. If it represents an object, it should be wrapped in outer braces: var json = @"{'MessageCodes': { 'Code1': 'Message 1', 'Code2': 'Message 2', 'Code3': 'Message 3', 'Code4': 'Message 4', 'Code5': 'Message 5', 'Code6': 'Message 6'}}"; var dict = JsonConvert.DeserializeObject<Test>(json); public class...
json,spring,deserialization,json-deserialization,fasterxml
Figured this one out. When making an HTTP POST using Curl as shown in the description (with the -d flag), the POST comes in with content type "application/x-www-form-urlencoded" (obvious in hindsight, since it's treated as a web form data). This triggers the Spring FormHttpMessageConverter message converter and MappingJackson2HttpMessageConverter converter is...
ios,objective-c,json,json-deserialization
Simply set @"author" to @"player.name".
c#,windows-phone-8,windows-7,windows-phone-8.1,json-deserialization
public class Invoice { public string TF { get; set; } public string BF { get; set; } public string MD { get; set; } public string EFM { get; set; } public string ATT { get; set; } public string FPK { get; set; } } public class Example...
c#,json,interface,json.net,json-deserialization
The $type encodes the fully-qualified type name, which will differ between the Client and Server if they're not using the same project to define these types (i.e. if each defines the type by itself rather than referencing a common assembly). In your case, in the client the fully-qualified name is...
c#,.net,json,json.net,json-deserialization
Solved it! The argument to deJSONizeModel is a FILE but JSON is required!
c#,json,deserialization,json-deserialization
JSON serialization does not on it's own handle complex typed (non string, int etc...) dictionaries, you would have to create your own Dictionary Serialization mechanism or do what you are doing via List<>. I ran across this same issue when trying to make a more efficient serializer/deserializer for WCF, while...
c#,json,deserialization,json-deserialization
logdetails in the first order is not an array... "legDetails": { "legNumber":1, "symbolInfo": { "symbol":"CSCO" } } should be like following: "legDetails": [{ "legNumber":1, "symbolInfo": { "symbol":"CSCO" } }] Update: So now the problem is you want to deserialize a json that can sometimes be array and sometimes may represent...
c#,.net,json,json.net,json-deserialization
The first code block isn't valid JSON. If you want JSON libraries to deal with your input you'll first need to convert it into valid JSON. If you're input is always going to look like that, you could use a regex to find the }\r\n\{ and replace it with a...
json,apache-camel,json-deserialization
In the upcoming Apache Camel 2.15 release you can more easily add custom Jackson modules to Camel. So in Java code you do JacksonDataFormat jackson = new JacksonDataFormat(); jackson.addModule(new GuavaModule()); And then use jackson in the route .unmarshal(jackson) Its documented here: http://camel.apache.org/json...