论坛首页 Web前端技术论坛

getJSON解析问题

浏览 3346 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-06-25  
我的json解析代码

$.getJSON("variable.cmd", function(data){
        for (i = 0; i < data.length; i++) {
            var id = data[i].id;
            var value = data[i].value;
            $("#list").append("<tr><td>" + id + "</td><td>" + value + "</td><td><input type='Button' value='Delete' onClick='deleteRow(this)' /><input type='Button' value='Edit' onClick='edit(this)' />" + "</td></tr>");
        }
        
    });



可以成功解析的数据

[{"id":1,"value":"<nobr xmlns='http://www.w3.org/1999/xhtml' xmlns:om='http://www.openmath.org/OpenMath' xmlns:am='http://www.activemath.org/namespaces/am_content' xmlns:omdoc='http://www.mathweb.org/omdoc' class='OMOBJ'><!--symbolpresentation to be opened with URL http://x/ActiveMath2/dict/show.cmd?id=mbase://openmath-cds/relation1/relation1eq_38_78 --><span xmlns='' xmlns:dc='http://purl.org/DC' class='varName'>y</span><sub xmlns='' xmlns:dc='http://purl.org/DC'>0</sub><span xmlns=''><img src='/ActiveMath2/images/blank.png' border='0' style='width: 0.166667em; height:  0.1em;'></span><a href='/ActiveMath2/search/show.cmd?id=mbase://openmath-cds/relation1/eq'    class='invisible'    title=''  	onclick='showInDictionary('mbase://openmath-cds/relation1/eq', 'html');return false;' 	xmlns='http://www.w3.org/1999/xhtml'>=</a><span xmlns=''><img src='/ActiveMath2/images/blank.png' border='0' style='width: 0.166667em; height:  0.1em;'></span>2</nobr>"},] 



不能解析到的数据
[{"id":1,"value":"<nobr xmlns='http://www.w3.org/1999/xhtml' xmlns:om='http://www.openmath.org/OpenMath' xmlns:am='http://www.activemath.org/namespaces/am_content' xmlns:omdoc='http://www.mathweb.org/omdoc' class='OMOBJ'><!--symbolpresentation to be opened with URL 
        http://x/ActiveMath2/dict/show.cmd?id=mbase://openmath-cds/relation1/relation1eq_38_78
        --><span xmlns='' xmlns:dc='http://purl.org/DC' class='varName'>y</span><sub xmlns='' xmlns:dc='http://purl.org/DC'>0</sub><span xmlns=''><img src='/ActiveMath2/images/blank.png' border='0' style='width: 0.166667em; height:  0.1em;'></span><a href='/ActiveMath2/search/show.cmd?id=mbase://openmath-cds/relation1/eq' 
    class='invisible'
    title=''
  	onclick='showInDictionary('mbase://openmath-cds/relation1/eq', 'html');return false;' 
  	xmlns='http://www.w3.org/1999/xhtml'
  	>=</a><span xmlns=''><img src='/ActiveMath2/images/blank.png' border='0' style='width: 0.166667em; height:  0.1em;'></span>2</nobr>"},]



后者实际上比能解析到的数据多了空格而已。。。但是是我的velocity的marco自动转换来了的。。。数据本身自带n多标签,所以也不好用xml,不知道这种情况下怎么用json取到。。。
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics