json library for java 1.4

那年仲夏 提交于 2020-01-30 05:15:36

问题


I'm using JCAPS 5.1.3 and only have Java 1.4 and need to handle with Json data. Unfortunately all libraries I've found use Java 1.5 and above. I just found lots of new implementations in this thread here, but which one works with 1.4.

Is there a stable and simple version to use with Java 1.4?


回答1:


An alternative is to use Retroweaver to make the jar compatible with Java 1.4:

http://retroweaver.sourceforge.net




回答2:


You can use my json library. It supports marshalling and unmarshalling to classes (with some restrictions) and parsing.

Marshalling:

Knight knight = new Knight();

knight.name = "Lancelot";
knight.weapon = new Weapon();
knight.weapon.metal = "true silver";
knight.weapon.name = "piercer";
knight.rank = 2;
knight.titles = new String[] { "noble", "round table member" };

Land goldshire = new Land();
goldshire.name = "GoldShire";
goldshire.surface = 45532.3;
Land direwood = new Land();
direwood.name = "Direwood";
direwood.surface = 472;
knight.lands = new Land[] { goldshire, direwood };

System.out.println("Test 1 : marshall simple class:");
String generated = JsonFactory.marshal(knight).toString();

Unmarshalling:

Knight knight = (Knight) JsonFactory.unmarshal(new FileTools().readFile("UnmarshallingTest1.json"), Knight.class);



回答3:


Xstream 1.2.2 supports Java 1.4. It's the only library I've found that supports Java 1.4. It definitely has its warts though.



来源:https://stackoverflow.com/questions/15501258/json-library-for-java-1-4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!