私はオブジェクトとしてキーとして最もよく表現された、このきちんとしたデータフォーマットを持っています。だから私は次のJSONを使用しようとしました:オブジェクトをJSONのキーとして使用するにはどうすればよいですか?
{
"blocks": {
"stone": {
{
"variant": ["bricks", "smooth"]
}: {
"sound": "guitar",
"particle": "guitar",
}
},
"dirt": {
{
"variant": "dirt"
}: {
"sound": "square",
"particle": "note",
"volume": 0.5
}
}
}
}
しかし、それは私にJsonSyntaxExceptionを与えます。私はGSON btwを使用しています。どうすればこの作品を作れますか?
データ構造:
import java.util.*;
public class Instrument {
private final String name;
private final String particle;
private final float volume;
public Instrument(String name, Optional<String> particle, Optional<Float> volume) {
this.name = name;
this.particle = particle.orElse("note");
this.volume = volume.orElse(1.0f);
}
/* getters and stuff */
}
public class BlockType {
private final String name;
private final BlockStateMatcher state;
public BlockType(String name, BlockStateMatcher state) {
this.name = name;
this.state = state;
}
/* getters and stuff */
}
import java.util.*;
public class BlockStateMatcher {
private final Map<PropertyMap, Instrument> states;
/* etc */
}
import java.util.*;
public class PropertyMap extends HashMap<Property<T>, List<PropertyValue<T>>> /* simplified */ {
/* etc */
}
有効なJSON構文ではありません。 http://jsonlint.com/ –
@ scaryWombatを参照してください。この構文を何とか使うことはできませんか? – SoniEx2
確かにjsonではありません。 –