1
我試圖將一個非常複雜的數組結構轉換爲JSON對象,但我不確定如何使用轉換。結構如下:Java - 從多個多維數組創建JSON對象
String[] foo = new String[10];
String[][] bar = new String[10][8];
String[][] blargh = new String[8][2];
// Populate foo
foo[0] = "foo1";
// ... and so on
bar[0][0] = "bar1";
// ... and so on
blargh[0][0] = "blargh1;"
// ... and so on
然後:
public JSONObject createJSONObject() {
/* Now, I would like to create an object with the structue:
[{
foo[0] : {
bar[0][0] : {
// more key-pair values, including blargh[0][0] and blargh[0][1]
},
bar[0][1] : {
// values of blargh[1][0] and blargh[1][1]
},
// etc...
},
foo[1] : {
bar[1][0] : {
/* primary index of bar will always match index of foo, as will the primary index of blargh */
},
// etc..
},
// etc..
}]
// return the JSON encoded object
}
這似乎是相當複雜的我,所以請告訴我,如果我的問題/代碼/結構混亂或不清晰。