deserialization

Deserialize JSON value without name

天大地大妈咪最大 提交于 2019-12-11 06:13:10
问题 How can I deserialize a string in C# that only have values and no name. It looks like this: The problem is that this stream of string does not have name and uses array. { "result": { "14400": [ [ 1502985600, 262.18, 262.18, 257, 257, 1096.0131 ], [ 1503000000, 257, 261.33, 254.8, 257, 1130.5897 ] ], "14405": [ [ 1503014400, 258.03, 261.5, 257.01, 257.01, 520.7805 ], [ 1503028800, 258, 260.98, 252.4, 259.56, 298.5658 ], ] ] } } 回答1: Just create a class like public class Root { public

Json.net Deserialize to JObject derived type

╄→гoц情女王★ 提交于 2019-12-11 06:02:07
问题 public class A : JObject {} and I have the folowing deserialization code using (StreamReader responseStreamReader = new StreamReader(stream)) { using (JsonReader reader = new JsonTextReader(responseStreamReader)) { JsonSerializer serializer = new JsonSerializer(); return serializer.Deserialize<A>(reader); } } But it throws Invalid Cast Exception in fact the deserializer just need to create new A() instead of new JObject() and do exactly the same after that, it would be enough for me. How can

RestSharp :Getting null from the result.Data althouh at the time of debug result has JSON returned

扶醉桌前 提交于 2019-12-11 05:56:19
问题 I am using RestSharp and trying to deserialize the JSON result set and when I run the code I'm getting null from the result.Data although at the time of debugging the result has JSON returned. private static void GetPanelList() { var client = new RestClient("http://CCCCCC.XXXXXX.com/API/v3/mailinglists/ML_dfgfghfghfh/contacts"); var request = new RestRequest(Method.GET); request.AddHeader("cache-control", "no-cache"); request.AddHeader("x-api-token", "JHFKFKJFYILIOROIY"); // IRestResponse

How can Spring RestController accept both JSON and XML?

喜夏-厌秋 提交于 2019-12-11 05:36:13
问题 I have a Spring controller that works great: @RestController @RequestMapping(value = "/widgets") class WidgetController { @RequestMapping(method = RequestMethod.POST) WidgetResponse createWidget(@Valid @RequestBody Widget widget) { // ... } } Here I can POST a JSON message and my widget instance gets created: { "name" : "Widget1", "type" : "spinning", "isFizz" : true } I would like this endpoint to also accept and deserialize XML widgets like so: <widget name="Widget1"> <type>spinning</type>

java gson replace password value while serialization

会有一股神秘感。 提交于 2019-12-11 05:33:58
问题 How can I replace the value of a password field with XXX while de-serializing an object with Gson? I found this post: Gson: How to exclude specific fields from Serialization without annotations that basically skips the field. This would be an option, but I still would prefer to replace the value with XXX I also tried this: GsonBuilder builder = new GsonBuilder().setPrettyPrinting(); builder.registerTypeAdapter(String.class, new JsonSerializer<String>(){ @Override public JsonElement serialize

Custom deserializer for requests with content-type application/x-www-form-urlencoded in Spring Boot

萝らか妹 提交于 2019-12-11 05:29:02
问题 I want to write a custom deserializer for some parameters in the requests of type application/x-www-form-urlencoded like used in case of requests of type application/json , with @JsonDeserialize(using = AbcDeserializer.class) annotation. I am using spring boot and Jackson, although I figured out that Jackson is not used here. I tried figuring out how spring deserializes object by default. But couldn't find a way. How does spring deserialize a request of type application/x-www-form-urlencoded

How to deserialize object with custom serializable properties?

青春壹個敷衍的年華 提交于 2019-12-11 05:16:07
问题 I'm trying to serialize/deserialize collection of interfaces, which basically is unsupported. I found a question on SO where a proposition is stated to provide a serializable wrapper properties for those properties which depends on interfaces. So that's what I have: public class Serialize { public Serialize() { this.SCollection = new SerializableInterfacesCollection<ObservableCollection<A>>(new ObservableCollection<A>()); } [XmlIgnore()] public ObservableCollection<A> Collection { get {

Always empty when using Deserialize on XmlSerializer

让人想犯罪 __ 提交于 2019-12-11 05:15:52
问题 I want to deserialize some XML that looks like this: XML: <bookings> <booking> <timeStart>2012/7/2 11:00:00</timeStart> <timeEnd>2012/7/2 12:00:00</timeEnd> </booking> <booking> <timeStart>2012/7/10 08:30:00</timeStart> <timeEnd>2012/7/10 10:30:00</timeEnd> </booking> </bookings> My code: var calUrlStr = "http://xxx.com?action=xxxxxx?x=1&y=2"; HttpWebRequest webRequest = GetWebRequest(calUrlStr); HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); XmlRootAttribute xRoot =

Deserializing nested lists with XmlSerializer

China☆狼群 提交于 2019-12-11 05:04:14
问题 I have a problem deserializing a list inside a list of elements with this structure: <Level> <Stage> <Sets> <Set></Set> <Set></Set> </Sets> </Stage> <Stage> <Sets> <Set></Set> <Set></Set> </Sets> </Stage> </Level> My current code is this: public class Level{ [XmlElement(ElementName="Stage")] public List<Stage> Stages = new List<Stage>(); } public class Stage{ [XmlAttribute("label")] public string label {get;set;} [XmlAttribute("pack")] public string pack {get;set;} [XmlElement(ElementName =

Charset messing up in VS 2008 JSON Deserialization

守給你的承諾、 提交于 2019-12-11 04:56:50
问题 I'm currently having a kind of weird issue. I've got a Mail Sending Web Service that is called by passing JSON to a certain URL. Since I got reported some accent issues in the mail sent since a few weeks, I'm inspecting on this issue. This looks like an encoding issue, that could be caused because we changed the SMTP Sender we're using. But there's also something that caught my attention, about the deserialization of the JSON into VS. In fact, I can't see the accent that are into the JSON.