我正在使用 GWT 构建应用程序,但我遇到了严重的速度问题,我认为它会非常快。我有一个 JSONObject,其数据结构如下(但要大得多):
{"nodeData" : [
{ "name":"one", "attributes":["uno","dos"]},
{"name":"two", "attributes":["tres"]}
]
}
我正在尝试遍历 JSON 对象以将所有属性存储到每个节点对象都具有的数组列表中,属性大小从 4 到 800 不等。
JSONObject JSONnode = nodeData.get(i).isObject();
Node node = new Node(JSONnode.get("name").toString();
JSONArray attributeArray = JSONnode.get("Attributes").isArray();
int attributeSize = attributeArray.size();
for(int j = 0; k < attributeSize; j++){
node.attributeArrayList.add(attributeArray.get(j).toString();
}
我正在执行的 for 循环大约需要一分钟,这似乎太长了,我不确定如何改进它。分钟是开发模式,不知道编译的时候会不会快点。
最佳答案
您尝试过使用叠加层吗?
GWT Coding Basics - JavaScript Overlay Types
您可以很容易地创建覆盖类型:-
// An overlay type
class Customer extends JavaScriptObject {
// Overlay types always have protected, zero-arg ctors
protected Customer() { }
// Typically, methods on overlay types are JSNI
public final native String getFirstName() /*-{ return this.FirstName; }-*/;
public final native String getLastName() /*-{ return this.LastName; }-*/;
// Note, though, that methods aren't required to be JSNI
public final String getFullName() {
return getFirstName() + " " + getLastName();
}
}
非常易于使用,我认为会比使用 JSONObject 对象快得多。
关于java - 通过 GWT 中的 JSONArray 进行缓慢迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7192024/