views:

427

answers:

0

Hey everyone,

I have succesfully been able to parse a JSON into a JSONTree, however, my tree shows the iterators. I have tried iterator.remove(), but I get the error:

Error: java.lang.UnsupportedOperationException: Remove not supported on this list

Can someone please look at my code, and let me know of anything I can do? Thanks!

public void processJSON(JSONValue jsonValue) {

 jsonTree.removeItems();
 jsonTree.setVisible(true);
 TreeItem treeItem = jsonTree.addItem(lb);
 addChildren(treeItem, jsonValue);
 // treeItem.setStyleName("JSON-JSONResponseObject");
 treeItem.setState(true);

 RootPanel.get("slot2").add(jsonTree);

}

@SuppressWarnings("unchecked")
private void addChildren(TreeItem treeItem, JSONValue jsonValue) {
 JSONArray jsonArray;
 JSONObject jsonObject;
 JSONString jsonString;

 if ((jsonArray = jsonValue.isArray()) != null) {
  for (int i = 0; i < jsonArray.size(); ++i) {
   TreeItem child = treeItem.addItem(getChildText("["
     + Integer.toString(i) + "]"));
   addChildren(child, jsonArray.get(i));
  }
 } else if ((jsonObject = jsonValue.isObject()) != null) {
  Set keys = jsonObject.keySet();
  for (Iterator iter = keys.iterator(); iter.hasNext();) {
   String key = (String) iter.next();
   // iter.remove();
   TreeItem child = treeItem.addItem(getChildText(key));
   addChildren(child, jsonObject.get(key));
  }
 } else if ((jsonString = jsonValue.isString()) != null) {
  // Use stringValue instead of toString() because we don't want
  // escaping
  treeItem.addItem(jsonString.stringValue());
 } else {
  // JSONBoolean, JSONNumber, and JSONNull work well with toString().
  treeItem.addItem(getChildText(jsonValue.toString()));
 }
}

private String getChildText(String text) {
 return "<span style='white-space:normal'>" + text + "</span>";
}

And here is what the JSON looks like when returned from the server:

 {"item":[{"Region 1":"behrk2"},{"Region 1":"sharkeym2"},{"Region 1":"behrk2"}]}

So in a tree, this would look like: item > 1 > Region...etc. I want to get rid of that 1

Thanks.