Son*_*Ex2 2 java json user-input gson javascript-objects
我有这种整洁的数据格式,最好用对象作为键表示.所以我尝试使用以下JSON:
{
"blocks": {
"stone": {
{
"variant": ["bricks", "smooth"]
}: {
"sound": "guitar",
"particle": "guitar",
}
},
"dirt": {
{
"variant": "dirt"
}: {
"sound": "square",
"particle": "note",
"volume": 0.5
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但它给了我一个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 */
}
Run Code Online (Sandbox Code Playgroud)
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 */
}
Run Code Online (Sandbox Code Playgroud)
import java.util.*;
public class BlockStateMatcher {
private final Map<PropertyMap, Instrument> states;
/* etc */
}
Run Code Online (Sandbox Code Playgroud)
import java.util.*;
public class PropertyMap extends HashMap<Property<T>, List<PropertyValue<T>>> /* simplified */ {
/* etc */
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
144 次 |
| 最近记录: |