gson

How to convert Badgerfish style JSON to XML in Java?

家住魔仙堡 提交于 2019-12-24 17:16:11
问题 My Java application takes XML input, and parses it using the simpleframework. I want it to accept JSON as well, therefore I want to convert the JSON to XML. Tags and attributes are important, therefore I use the Badgerfish convention. This works well in Python with xmljson, but I can't find a decent package to do this. GSON doesn't seem to have a Badgerfish implementation. This topic doesn't provide any tag/attribute retaining packages, the topic is a bit old as well. Which Java packages can

Read arbitrarily json data to a javafx treeview,and only show the first element of any array in it

大城市里の小女人 提交于 2019-12-24 16:41:29
问题 I need to show a json file on a javafx treeview,the structure of the json is unknown.Like the web site: json viewer site I show the tree for user to select path of a value(like xpath of xml),so if the json is too big,I only need to show the first element of any array in json. for example,the original data is: { name:"tom", schools:[ { name:"school1", tags:["maths","english"] }, { name:"school2", tags:["english","biological"] }, ] } I want to show: again:the structure of json is unknown,it is

null pointer exception-parsing json with gson android

混江龙づ霸主 提交于 2019-12-24 15:13:06
问题 Hi i am trying to parse Json using gson library.My Json String is this { "data": [ { "atb_atestwebservice_cities": [ { "id": "3", "cities": "Ajmer", "date": "2012-03-01 19:30:32" } ] }, { "atb_atestwebservice_states": [ { "id": "2", "states": "goa", "date": "2012-02-28 12:53:51" } ] } ] } With following classes public class Cities { @SerializedName("id") private String id; @SerializedName("cities") private String cities; @SerializedName("date") private String date; public Cities(String id

Java: Gson custom serializer and deserializer special requirement

南楼画角 提交于 2019-12-24 13:32:08
问题 I know how to implement JsonDeserializer and JsonSerializer, but here is what I want to do: This is the setup: public class classA { public String a; public classB clazzB; } public class classB { public String c; public String d; public String e; public String f; } I want to serialize (and deserialize analog to this) classA like this: when serializing classA it should serialize a part of classB with it aswell, say variables c and d Since I know how to do that (using transient for e and f)

Android converting an object to JSON format with GSON not working

送分小仙女□ 提交于 2019-12-24 13:06:06
问题 I am trying to convert an object to a JSON format using GSON. I will then send the JSON to the webservice written in php. Unfortunately for some reason, the method gson.toJson(object) is not working. I have this java object - intervention (This contains several fields of types String, Date, Time and bitmaps). When I try to do this: Gson gson = new Gson(); String json = gson.toJson(intervention); I get this in the gson variable: gson={serializeNulls:falsefactories:[Factory[type=com.google.gson

Gson/Retrofit parse variable JSON

岁酱吖の 提交于 2019-12-24 12:45:28
问题 I'm struggling in parsing a JSON Object with variable content to a Java Object. Normally, I'd try to map a JSON Object to a POJO, however in this case I don't know what to do. My JSON looks like this: "parts": [ [ "text", "http://www.example.com/" ], [ "page", [ "http://www.example.com/", "\n\t\n\t\t\n\t\t\tSome of the Page Content preview here...", "", "/path/to/picture.jpg" ] ], [ "text", "Another String here " ] ] Running this piece of code trough a typical Json to Java Object converter

convert stringified json to jsonArray using kotlin in android

爱⌒轻易说出口 提交于 2019-12-24 12:09:16
问题 I'm trying to convert this string to jsonArray. for (jsonIndex in 0..(jsonArray.length() - 1)) { Log.d("JSON", jsonArray.getJSONObject(jsonIndex).getString("translation").toString()) } however, this turns out not to be an object but a string, I'm quite sure its because of the way the someString is. Is there a way i could either fix this string or how should i proceed further? val wordReview = "[\n \"{\\n \\\"assignUser\\\" : false,\\n \\\"transliteration\\\" : \\\"wa\\\",\\n \\\"lessonNumber\

Android Studio MalformedJsonException

落花浮王杯 提交于 2019-12-24 10:44:37
问题 Just today I was on Android Studio working on a project, when my computer suddenly crashed in the middle of an upload. Ever since I rebooted it, the Gradle Console has been returning this same error: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.RuntimeException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 I cannot make any sense out of this error, and could not find anyone else with the

Problem deserializing Bugzilla JSON using Google's Gson

旧街凉风 提交于 2019-12-24 09:59:22
问题 I'm hitting a problem in JSON I'm getting back from a Bugzilla server because it sometimes returns "text" : {} and sometimes "text" : "blah blah blah". Bugzilla returns the former if no description was given for a bug. I'm mystified why it doesn't come back as the much more sensible "text" : "" but it does and that's it. If I have a String named text in the target object for Gson, it objects when it sees the {} case because it says that's an object and not a String: Exception in thread "main"

Library import issues

走远了吗. 提交于 2019-12-24 09:54:07
问题 I've copied my work-project and setup app at home. I'm using Gson and it's located in /lib folder and referenced as library. However, during the runtime the Gson object couldn't be instantiated and console gave me the following 04-13 01:47:50.948: E/AndroidRuntime(386): FATAL EXCEPTION: main 04-13 01:47:50.948: E/AndroidRuntime(386): java.lang.NoClassDefFoundError: com.google.gson.Gson Any suggestions, please? ps I'm using Eclipse and I've already tried "clean"ing the project, resetting Gson