deserialization

System.MissingMethodException: Error while deserialization of json array

岁酱吖の 提交于 2019-12-20 02:27:33
问题 I am getting error while deserializing jsonString. Error is Type 'oodleListingsUser' is not supported for deserialization of an array. My code of deserialization is string jsonString = new WebClient().DownloadString("http://api.oodle.com/api/v2/listings?key=TEST&region=region_value&category=category_value&format=json"); JavaScriptSerializer ser = new JavaScriptSerializer(); jsonOodleApi p = ser.Deserialize<jsonOodleApi>(jsonString); My class defination of jsonOodleApi is public class

How to get a part of JSON as a plain text using Jackson

三世轮回 提交于 2019-12-20 01:52:09
问题 I've got a following JSON from API: "hotel_data": { "name": "Hotel Name", "checkin_checkout_times": { "checkin_from": "14:00", "checkin_to": "00:00", "checkout_from": "", "checkout_to": "12:00" }, "default_language": "en", "country": "us", "currency": "USD", "city": "Miami" } I'm using Jackson library to deserialize this JSON to Java object. I don't want to create a special class for checkin_checkout_times object. I just want to get it as a plain text. Like this "checkin_from": "14:00",

Gson fromJson() returns object with null attrubutes

守給你的承諾、 提交于 2019-12-19 13:49:51
问题 I'm trying to create some Java objects using this line: Quiz currentQuiz = gson.fromJson(json, Quiz.class); But the all I get is this: Here are my object classes: Quiz: public class Quiz { private String ref; private String broadcast_dt; private Question[] questions; public Quiz() { // TODO Auto-generated constructor stub } public String getRef() { return ref; } public void setRef(String ref) { this.ref = ref; } public String getBroadcast_dt() { return broadcast_dt; } public void setBroadcast

Deserializing arbitrary object json arrays in inner classes with Gson or nested inner class

谁说我不能喝 提交于 2019-12-19 11:43:41
问题 I am having troubles when I try to deserialize one Json string with Gson. The string goes something like this (Note: I just simplified it, but leaving the part I am having troubles with and because of that, there might be Json syntaxis errors, but I have checked with an online validator that the string I am working with is OK): // let's call this "container" json element { "context": "context", "cpuUsage": cpuUsageValue, "name": "thename", "rates": { "definition": [ { "key": "name", "type":

Changing instance state does not get reflected in serialized object

自作多情 提交于 2019-12-19 09:53:46
问题 I wrote following simple code public static void main(String args[]) throws FileNotFoundException, IOException, ClassNotFoundException { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("data.txt"))); Human human = new Human(); human.setAge(21); human.setName("Test"); System.out.println("Human : " + human); oos.writeObject(human); human.setName("Test123"); oos.writeObject(human); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("data.txt"

Deserializing JSON to object with no default constructor in ASP.NET MVC 3

半世苍凉 提交于 2019-12-19 09:16:46
问题 There are quite a few questions around JSON deserialization but a lot of them seem to be for MVC 1 or MVC 2. I don't seem to have found a satisfactory answer to this specifically for MVC 3. I have an object with immutable properties and no default constructor, which I want to deserialize to in an ASP.NET MVC 3 application. Here is a simplified version: public class EmailAddress { public EmailAddress(string nameAndEmailAddress) { Name = parseNameFromNameAndAddress(nameAndEmailAddress); Address

How do deserialize this JSON into an object?

徘徊边缘 提交于 2019-12-19 09:09:42
问题 I'm trying to use JSON.Net to deserialize a JSON object into a C# object. The object I want to create is MonthlyPerformance which contains a list of Type , which contains a list of Categories , which in turn contains a list of Funds . They are defined as: public class MonthlyPerformance { public List<Type> Types { get; set; } } public class Type { public int Id { get; set; } public string CountryId { get; set; } public string Name { get; set; } public List<Category> Categories { get; set; }

In C# how can I deserialize this json when one field might be a string or an array of strings?

不打扰是莪最后的温柔 提交于 2019-12-19 09:06:26
问题 I have an asp.net-mvc website and i am reading in Json string from a Database. Here is the following json in a DB. It could look like this: {"description": "Test", "contacts": ["joe@gmail.com", "bill@yahoo.com"], "enabled": true} or this: {"description": "Test", "contacts": "joe@gmail.com, bill@yahoo.com", "enabled": true} so as you can see, the contacts field is either: a string (with items separated by commas) an array of strings. I want to convert to this class: public class MyJob { public

serialization/deserialization mechanism

痴心易碎 提交于 2019-12-19 08:17:19
问题 Say, I have a class X which has a field value, that is, class X implements Serializable { private int value; // ... } Further it has getters and setters not displayed here. This class is serialized. At the deserialzation, end same class has value field and access specifier is public. Further, this class does not have getters and setters. So, my questions are: Does deserialization fail in case the access specifier of the field changes OR some or all of the methods go missing in the class at

Deserialize element value as string although it contains mixed content

佐手、 提交于 2019-12-19 08:10:08
问题 Assuming an XML like this: <my:Root xmlns:my="http://foo/bar"> <my:FieldBasic>content</my:FieldBasic> <my:FieldComplex> <html xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml"> <div><h1>content</h1></div> </html> </my:FieldComplex> <my:Root> and a class like: [Serializable] [XmlType(AnonymousType = true, Namespace = "http://foo/bar")] [XmlRoot(ElementName = "Root", Namespace = "http://foo/bar", IsNullable = false)] public class MyRoot { public string FieldBasic { get; set; } public