问题
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