【发布时间】:2014-04-30 16:00:15
【问题描述】:
我正在尝试使用 JSON 将 javascript 项目数组传递给 java 服务器。 我的服务器收到以下字符串:
[
{"attr1":"SomeValue1","attr2":"SomeValue2"},
{"attr1":"SomeValue3","attr2":"SomeValue4"}
]
我正在尝试使用JsonArray,但可能做错了(我没有在此处添加我的代码,因为它可能只是愚蠢的)。
谁能给我正确的方法来创建对我的字符串中的值进行迭代?
编辑: 根据要求,我的愚蠢代码:
jsnobject = new JSONObject(items); //items is the string described above
JSONArray jsonArray = jsnobject.getJSONArray("");
if(jsonArray != null){
for(int i=0 ; i<jsonArray.length();i++){
JSONObject explrObject = jsonArray.getJSONObject(i);
System.out.println("name = "+explrObject.get("fileName"));
}
}
【问题讨论】:
-
我没有在这里添加我的代码,因为它可能只是愚蠢的我们从制作愚蠢的东西中学习并将它们转换成awesome 。发布您的代码,我们将在此过程中为您提供帮助。
-
您必须在此处发布您的代码,无论您认为它看起来多么愚蠢,否则您的问题可能会被关闭。
-
你使用什么 JSON 库?当然
JSONObject和JSONArray类必须来自某个地方。 -
@T-Bull json.org
标签: java javascript arrays json