使用JSON在HTML数据属性中传递数据

时间:2013-05-25 11:05:56

标签: javascript json

已解决 - 请参阅此帖后的最新评论。

我正在尝试传递和检索隐藏变量中的JSON数据并遇到奇怪的情况。我一直绞尽脑汁,到处搜寻,找出原因 - 我确定它有些愚蠢,但我想不出是什么......:

  1. 第504行& 508显示正确的数据(除了描述字段是唯一被更改的字段),但是第509行显示了_attachments下的另一个对象,而另外两个对象中没有 - 为什么?
  2. 第509行 - 标题行描述文本与对象正文中的描述文本不同 - 正文描述是正确的。
  3. 原木取自铬,但firefox表现出相同的行为。 请参阅下面的代码和控制台日志。

    503 var pp = $("#new-event-page").find("input[name=event_data]").val();
    504 console.log(pp);
    505 // comment
    506 var paramx = JSON.parse(pp);
    507 //comment
    508 console.log(JSON.stringify(paramx));
    509 console.log(paramx);
    

    控制台日志的输出如下(在一些手动格式化之后):

    testa.js:504--{"name":"Untitled-1369464011",
                   "description":"Previously aadded image - only this text is updated",
                   "occurred":"2013-05-25",
                   "group":"empty",
                   "category":"empty",
                   "_attachments":{"globe.png":{"content_type":"image/png",
                                                "digest":"md5d8ba0496f16bdf74d6310432abf2a530"}},
                    "_id":"0C1CA0F4-2DF4-46F2-9D35-415674D6452A",
                    "_rev":"5-1d108457b606cc4388160ca46ffefbbf"}
    testa.js:508--{"name":"Untitled-1369464011",
                   "description":"Previously aadded image - only this text is updated",
                   "occurred":"2013-05-25",
                   "group":"empty",
                   "category":"empty",
                   "_attachments":{"globe.png":{"content_type":"image/png",
                   "digest":"md5-d8ba0496f16bdf74d6310432abf2a530"}},
                   "_id":"0C1CA0F4-2DF4-46F2-9D35-415674D6452A",
                   "_rev":"5-1d108457b606cc4388160ca46ffefbbf"}
    testa.js:509--Object {name: "Untitled-1369464011", description: "Previously aadded image - only this text is updated", occurred: "2013-05-25", group: "empty", category: "empty"…}
        _attachments: Object
           globe.png: Object
              content_type: "image/png"
              __proto__: Object
           opAAAAAElFTkSuQmCC: Object
              content_type: undefined
              __proto__: Object
         __proto__: Object
         _id: "0C1CA0F4-2DF4-46F2-9D35-415674D6452A"
         _rev: "6-001ee0c89c5b9dbe2b06e5b926ad446d"
         category: "empty"
         description: "Previously aadded image - only this text is updated -pass 2"
         group: "empty"
         name: "Untitled-1369464011"
         occurred: "2013-05-25"
         __proto__: Object
    

1 个答案:

答案 0 :(得分:0)

嗯,我在FF 21看到没有错误: http://jsfiddle.net/A3tex/

给出: enter image description here