Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
已解析的json对象仅返回最后一个元素_Json_Jquery Mobile_Getjson - Fatal编程技术网

已解析的json对象仅返回最后一个元素

已解析的json对象仅返回最后一个元素,json,jquery-mobile,getjson,Json,Jquery Mobile,Getjson,循环通过getJSON结果在中显示json对象-仅返回最后一个元素-json对象具有完整结果?通过数据循环[i]应该给我所有 <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, user-scalable=no"> <link href="http://jqmdesigner.appspot.

循环通过getJSON结果在
  • 中显示json对象-仅返回最后一个元素-json对象具有完整结果?通过数据循环[i]应该给我所有

    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, user-scalable=no">
        <link href="http://jqmdesigner.appspot.com/gk/lib/jquery.mobile/1.4.2/flatui/jquery.mobile.flatui.css" rel="stylesheet" type="text/css" />
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
        <title>get the html from a website</title>
        <script>
            $( document ).ready(function() {
            $.getJSON("tt_json.php", function(data){
                for (var i = 0; i < data.length; i++) {
                    $.each(data[i], function(key, val) {
                        //alert(key + ":" + val); 
                        $('#myUL').html("<li>" + key + " : " + val + "</li>");  
                    });
                } 
            });
    
        </script>
    </head>    
    <body>          
    <!-- Page: home  -->
        <div id="home" data-role="page">
            <div data-role="header" data-position="fixed" data-theme="b">
            <h3>GET WEB DATA</h3>
            </div>
            <div role="main1" id="mainone" class="ui-content"> 
                <ul data-role='listview' id='myUL' data-inset='true' class='ui-listview ui-listview-inset ui-corner-all ui-shadow'>
                </ul>
            </div>
            <div role="main" id="mainzero" class="ui-content"> 
            </div>
        </div>           
    </body>
    
    
    从网站获取html
    $(文档).ready(函数(){
    $.getJSON(“tt_json.php”),函数(数据){
    对于(变量i=0;i”+key+”:“+val+””);
    });
    } 
    });
    获取WEB数据
    

    您似乎在javascript函数的循环中设置了id为
    myUL
    的html标记。这每次都会覆盖该标记的内部html。请尝试添加
    li
    元素,而不是覆盖。

    $('#myUL')更改为
    $('#myUL').append
    修复了它,谢谢你为我指明了正确的方向。