我在java中创建了JSONArray,如下所示:
array = new JSONArray();
for (int i = 0; i < master.size(); i++) {
Map option = (Map) master.get(i);
String key = (String) option.get("KEY");
String text = key + ": " + (String) option.get("NAME");
JSONObject object = new JSONObject();
object.put("key", modalityKey);
object.put("text", text);
array.add(object);
}
然后我在JavaScript中使用var list = "<%=array%>";
,但是我收到了错误SCRIPT1004,IE F12控制台上列表中的数据如下,我不知道哪里有错误,请帮助我。
var list = "[
{"key":"C","text":"C: C1"},
{"key":"E","text":"E: E2"},
{"key":"G","text":"G: G3"},
{"key":"H","text":"H: H4"},
{"key":"I","text":"I: I5"},
{"key":"K","text":"K: K6"},
{"key":"L","text":"L: L7"},
{"key":"N","text":"N: N8"},
{"key":"P","text":"P: P9"},
{"key":"Q","text":"Q: Q10"},
{"key":"R","text":"R: R11R"},
{"key":"S","text":"S: S12"},
{"key":"T","text":"T: T13"},
{"key":"U","text":"U: U14"},
{"key":"V","text":"V: V15"},
{"key":"X","text":"X: X16"},
{"key":"Y","text":"Y: Y17"},
{"key":"Z","text":"Z: Z18"}]";
答案 0 :(得分:-1)
将int更改为var in:
for (int i = 0; i < master.size(); i++) {}
新代码:
for (var i = 0; i < master.size(); i++) {}
记住我或索引是一个不是整数(int)的变量。