Tapestry
  1. Tapestry
  2. TAPESTRY-1053

Can't use IJSONWriter to write a JSONArray object.

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.1.1
    • Fix Version/s: 4.1.1
    • Component/s: None
    • Labels:
      None

      Description

      I want to write an array (x,x,x,x},{y,y,y,y) using IJSONWriter,I find I can't do it.

      I want to use JSONArray to create json string.

        Activity

        Hide
        Jun Tsai added a comment -

        I think we can reference http://www.json.org/java/org/json/JSONWriter.java to do it.

        Show
        Jun Tsai added a comment - I think we can reference http://www.json.org/java/org/json/JSONWriter.java to do it.
        Hide
        Jesse Kuhnert added a comment -

        I don't think the syntax you've shown is valid JSON. An array looks like:

        [x,x,x,]

        Properties can be specified within {}, but they need to be in the form of key/value pairs like:

        {key:value,key2:value2,keyarray:[1,2,3]}

        I've been using arrays in the validation logic. You can call accumulateProperty or just instantiate a new JSONArray if you want.

        Show
        Jesse Kuhnert added a comment - I don't think the syntax you've shown is valid JSON. An array looks like: [x,x,x,] Properties can be specified within {}, but they need to be in the form of key/value pairs like: {key:value,key2:value2,keyarray:[1,2,3]} I've been using arrays in the validation logic. You can call accumulateProperty or just instantiate a new JSONArray if you want.
        Hide
        Jun Tsai added a comment -

        But I don't need key.

        I want to implement dojo tree widget in tapestry.The tree need json object array without key.

        How to implement?

        Show
        Jun Tsai added a comment - But I don't need key. I want to implement dojo tree widget in tapestry.The tree need json object array without key. How to implement?
        Hide
        Jun Tsai added a comment -

        In dojo TreeLoadingController

        loadProcessResponse: function(node, result, callObj, callFunc) {
        .............
        .............

        var newChildren = result;

        if (!dojo.lang.isArray(newChildren))

        { dojo.raise('loadProcessResponse: Not array loaded: '+newChildren); }

        for(var i=0; i<newChildren.length; i++)

        { // looks like dojo.widget.manager needs no special "add" command newChildren[i] = dojo.widget.createWidget(node.widgetType, newChildren[i]); node.addChild(newChildren[i]); }

        So I think the syntax should be [

        {"title":"title","isFolder":"true"}

        ,

        {"title":"title","isFolder":"true"}

        ,

        {"title":"title","isFolder":"true"}

        ,

        {"title":"title","isFolder":"true"}

        ]

        Show
        Jun Tsai added a comment - In dojo TreeLoadingController loadProcessResponse: function(node, result, callObj, callFunc) { ............. ............. var newChildren = result; if (!dojo.lang.isArray(newChildren)) { dojo.raise('loadProcessResponse: Not array loaded: '+newChildren); } for(var i=0; i<newChildren.length; i++) { // looks like dojo.widget.manager needs no special "add" command newChildren[i] = dojo.widget.createWidget(node.widgetType, newChildren[i]); node.addChild(newChildren[i]); } So I think the syntax should be [ {"title":"title","isFolder":"true"} , {"title":"title","isFolder":"true"} , {"title":"title","isFolder":"true"} , {"title":"title","isFolder":"true"} ]
        Hide
        Jesse Kuhnert added a comment -

        Hmmm...I see your point. (Thanks for pointing out the controller section, reading that tree widget code gives me a headache.)

        This introduces new "problems". I'll have to see what can be done.

        Show
        Jesse Kuhnert added a comment - Hmmm...I see your point. (Thanks for pointing out the controller section, reading that tree widget code gives me a headache.) This introduces new "problems". I'll have to see what can be done.
        Hide
        Andreas Andreou added a comment -

        I have the feeling that
        {0:

        {"title":"title","isFolder":"true"}

        , 1:{"title":"title","isFolder":"true"}}
        might just work

        Show
        Andreas Andreou added a comment - I have the feeling that {0: {"title":"title","isFolder":"true"} , 1:{"title":"title","isFolder":"true"}} might just work
        Hide
        Jun Tsai added a comment -

        I had tested it. It can't work.dojo debug message is "FATAL: loadProcessResponse: Not array loaded: [object Object]".

        Show
        Jun Tsai added a comment - I had tested it. It can't work.dojo debug message is "FATAL: loadProcessResponse: Not array loaded: [object Object] ".
        Hide
        Jesse Kuhnert added a comment -

        Changed interface for IJSONWriter, can now call writer.array() to get access to the array type response.

        Show
        Jesse Kuhnert added a comment - Changed interface for IJSONWriter, can now call writer.array() to get access to the array type response.

          People

          • Assignee:
            Jesse Kuhnert
            Reporter:
            Jun Tsai
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development