我有一个 Android 游戏,我想在其中将关卡存储为静态 Java 类。 Java 中以下 Javascript 对象的等价物是什么?
var Levels = {
Level1:{
shapes:[
{
bodytype : "dynamic",
h : "50.0000",
nameid : "hofN7-1",
props : {
id : "properties"
},
rotation : "0.0000",
type : "square",
uid : "Av2EZQh",
w : "50.0000",
x : "20.0000",
y : "20.0000"
},
{
bodytype : "dynamic",
h : "50.0000",
nameid : "hofN7-2",
props : {
gravMassScale : "2",
id : "properties",
inertia : "2",
isBullet : true,
torque : "2",
velocity : {
x : "2",
y : "2"
}
}
}
...
最佳答案
如果你正在寻找接近 JS 存储对象的方式,你可以试试 JSONObject 类:
http://json.org/javadoc/org/json/JSONObject.html
撇开语法到语法的映射不谈,从工程的 Angular 来看,我会将级别存储在级别的映射中,如下所示:
HashMap<String, Level> myLevels = new HashMap<String, Level>();
关于java - Java 相当于 Javascript 中的多维对象是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16316455/