GIS_eagle

how to read the chinese from the json file

Discussion created by GIS_eagle on Aug 27, 2012
Latest reply on Aug 27, 2012 by jacobsj
I want read the Chinese from Json file.
my Json file like this:

       {
             identifier: 'id',
             label: 'name',
             type:"esriFieldTypeString",
             items: [
                { id: 1, name:"????",type:"esriFieldTypeString"
                  
                }
            ]
        }
the code like this:

         require(["dojo/store/JsonRest", "dojo/store/Observable", "dijit/Tree", "dijit/tree/dndSource", "dojo/query", "dojo/domReady!"],
             function(JsonRest, Observable, Tree, dndSource, query) {

              usGov = JsonRest({
                  target: "data/root.json",
                  mayHaveChildren: function(object) {
                      // see if it has a children property
                      return "children" in object;
                  },
                  getChildren: function(object, onComplete, onError) {
                      // retrieve the full copy of the object
                      this.get(object.id).then(function(fullObject) {
                          // copy to the original object so it has the children array as well.
                          object.children = fullObject.children;
                          // now that full object, we should have an array of children
                          onComplete(fullObject.children);
                      }, function(error) {
                          // an error occurred, log it, and indicate no children
                          console.error(error);
                          onComplete([]);
                      });
                  },
                  getRoot: function(onItem, onError) {
                      // get the root object, we will do a get() and callback the result
                      this.get("root").then(onItem, onError);
                  },
                  getLabel: function(object) {
                      // just get the name
                      return object.name;
                  },
                  put: function(object, options) {
                      this.onChildrenChange(object, object.children);
                      this.onChange(object);
                      return JsonRest.prototype.put.apply(this, arguments);
                  },
                  remove: function(id) {
                      // We call onDelete to signal to the tree to remove the child. The
                      // remove(id) gets and id, but onDelete expects an object, so we create
                      // a fake object that has an identity matching the id of the object we
                      // are removing.
                      this.onDelete({ id: id });
                      // note that you could alternately wait for this inherited add function to
                      // finish (using .then()) if you don't want the event to fire until it is
                      // confirmed by the server
                      //                  return JsonRest.prototype.remove.apply(this, arguments);
                  }
              });
              tree = new Tree({
              style: 'width:300px;height:350px',
                  model: usGov,
                  dndController: dndSource
              }, "tree"); // make sure you have a target HTML element with this id
              tree.startup();
              query("#add-new-child").on("click", function() {
                  var selectedObject = tree.get("selectedItems")[0];
                  if (!selectedObject) {
                      return alert("No object selected");
                  }
                  usGov.get(selectedObject.id).then(function(selectedObject) {
                      selectedObject.children.push({
                          name: "New child",
                          id: Math.random()
                      });
                      usGov.put(selectedObject);
                  });

              });
              query("#remove").on("click", function() {
                  var selectedObject = tree.get("selectedItems")[0];
                  if (!selectedObject) {
                      return alert("No object selected");
                  }
                  usGov.remove(selectedObject.id);
                 
              });
              tree.on("dblclick", function(object) {
                  object.name = prompt("Enter a new name for the object");
                  usGov.put(object);
              }, true);
          });
      }

how to do?

Outcomes