json-lib

jdk1.4下json lib使用时所需的jar包版本

孤街醉人 提交于 2020-02-29 09:16:38
因需要在遗留系统(jdk1.4环境)使用到json和java对象的互转,想到用json-lib,遂到官网查看相关文档。 经实践,jdk1.4环境下,正常使用json-lib工具包,需如下jar包: json-lib-2.3-jdk13.jar commons-beanutils-1.8.0.jar commons-collections-3.2.1.jar commons-lang-2.5.jar ezmorph-1.0.6.jar commons-logging.jar 注:json-lib最好不要使用 2.4 版本的(json-lib-2.4-jdk13.jar),在jdk1.4下解析json字符串会有问题。会报如下错误: 问题根源:remove是java.lang.ThreadLocal类的方法,但是jdk1.4中没有这个方法的实现,jdk1.5中才实现。使用会低版本的json-lib就不存在此bug。 来源: oschina 链接: https://my.oschina.net/u/574750/blog/806285

Convert json string to Java Map(JSONLib)

天涯浪子 提交于 2020-01-01 08:02:51
问题 How can I convert json string to Java Map using JSON-lib(http://json-lib.sourceforge.net/) ? I can convert to DynaBean: JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( str ); DynaBean bean = (DynaBean) JSONSerializer.toJava( jsonObject ); but I have not found a method to convert directly to Java Map Edit: I have found the solution: JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( str ); Map<String, Object> myMap = (Map<String, Object>) JSONObject.toBean(jsonObject, Map

parsing json with java

南楼画角 提交于 2019-12-29 00:41:08
问题 I am a newbie to json parsing, I have grabbed a json string from a request and now I need to parse it with java. I'm using json-lib for this. But I'm really stuck as I'm not familiar with it. I need to extract following data 1. name (hotel name) 2. starRating 3. geoPoint I used following java code for that but it's not giving me the result I need, please someone help me... Thanks a lot! java code (s is the json string I get) JSONObject json = (JSONObject) JSONSerializer.toJSON(s); JSONArray

Invalid character while converting from JSON to XML using jsonlib

南楼画角 提交于 2019-12-13 17:30:38
问题 I'm trying to convert a JSON string to XML using jsonlib in Java. JSONObject json = JSONObject.fromObject(jsonString); XMLSerializer serializer = new XMLSerializer(); String xml = serializer.write( json ); System.out.println(xml); The error that I get is nu.xom.IllegalNameException: 0x24 is not a legal NCName character The problem here is that I have some properties in my JSON that are invalid XML characters. eg. I have a property named "$t". The XMLSerializer throws the exception while

Can't parse JSON property “null”

99封情书 提交于 2019-12-10 18:04:13
问题 I faced with one trouble when tried to parse JSON "null" property, please help me to understand what's the real problem. I had a following JSON: { "properties" : { "null" : { "value" : false } } } I used http://jsonlint.com to validate that this JSON is valid. I tried to parse it from java: import net.sf.json.JSONObject; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException { String st = "{" + " 'properties' : {" + " 'null' : {" + " 'value'

Apache Camel: XMLJSON conversion for empty tags to strings instead of arrays

给你一囗甜甜゛ 提交于 2019-12-10 17:15:33
问题 When using the Camel XMLJSON library and when converting an XML message to JSON using the unmarshal option. The application is converting the empty tags to empty JSON arrays. Is there a way to override this behavior to instead convert it into empty strings. For example <person> <first_name>john</first_name> <last_name/> </person> converts to { "first_name": "john", "last_name": [] } instead of the below { "first_name": "john", "last_name": "" } How can this default behavior be overridden to

JSON-lib escaping / preserving strings

心不动则不痛 提交于 2019-12-09 12:56:14
问题 I am using JSON-lib library for java http://json-lib.sourceforge.net I just want to add simple string which can look like JSON (but i do not want library to automatically figure out that it might be json and just to treat it as string). Looking into source of library I can't find the way to do it without ugly hacks. example: JSONObject object = new JSONObject(); String chatMessageFromUser = "{\"dont\":\"treat it as json\"}"; object.put("myString", chatMessageFromUser); object.toString() will

parsing json with java

淺唱寂寞╮ 提交于 2019-11-28 12:37:08
I am a newbie to json parsing, I have grabbed a json string from a request and now I need to parse it with java. I'm using json-lib for this. But I'm really stuck as I'm not familiar with it. I need to extract following data 1. name (hotel name) 2. starRating 3. geoPoint I used following java code for that but it's not giving me the result I need, please someone help me... Thanks a lot! java code (s is the json string I get) JSONObject json = (JSONObject) JSONSerializer.toJSON(s); JSONArray jarray = json.getJSONArray("hotels"); for(int i=0 ; i < jarray.size(); i++) { System.out.println("jarray

How to force JSON-lib's JSONObject.put(..) to escape a string containing JSON?

血红的双手。 提交于 2019-11-28 07:36:48
问题 When using JSON-lib's JSONObject , how can I stop the put method from storing a String which contains JSON as JSON rather than as an escaped string? For instance: JSONObject obj = new JSONObject(); obj.put("jsonStringValue","{\"hello\":\"world\"}"); obj.put("naturalStringValue", "\"hello world\""); System.out.println(obj.toString()); System.out.println(obj.getString("jsonStringValue")); System.out.println(obj.getString("naturalStringValue")); prints: {"jsonStringValue":{"hello":"world"},