Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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
Jquery 将JSON解释为Kendo UI Mobile Listview_Jquery_Ajax_Json_Kendo Ui_Kendo Mobile - Fatal编程技术网

Jquery 将JSON解释为Kendo UI Mobile Listview

Jquery 将JSON解释为Kendo UI Mobile Listview,jquery,ajax,json,kendo-ui,kendo-mobile,Jquery,Ajax,Json,Kendo Ui,Kendo Mobile,我正在尝试将JSON数据转换为Kendo UI Mobile Listview。我的php脚本输出以下数据: [{"eventID":"1","name":"test","time":"12:00:00","category":"####","subcategory":"####","description":"Event for testing purposes","locationID":"1","picturePath":"http:\/\/####\/~z3370257\/images\

我正在尝试将JSON数据转换为Kendo UI Mobile Listview。我的php脚本输出以下数据:

[{"eventID":"1","name":"test","time":"12:00:00","category":"####","subcategory":"####","description":"Event for testing purposes","locationID":"1","picturePath":"http:\/\/####\/~z3370257\/images\/1.jpg"},{"eventID":"2","name":"test2","time":"13:00:00","category":"####","subcategory":"SEIT","description":"Event for testing purposes2","locationID":"1","picturePath":"http:\/\/####\/~z3370257\/images\/1.jpg"}]
使用与我的应用程序相同的html css和javascript文件


我的问题是,我需要在我的传输和读取方法中加入什么才能让它正确解释数据

你的剑道密码很好。只有两个问题:

  • 服务返回的数据不是正确的JSON。它应该这样编码:

                    [{ 
                    "category": "123",
                    "description": "Event for testing purposes",
                    "eventID": "1",
                    "locationID": "1",
                    "name": "Kendo",
                    "picturePath": "https://si0.twimg.com/profile_images/1514396238/KendoUI-Figure.png",
                    "subcategory": "SEIT",
                    "time": "12:00:00"
                } ,
    
                {
                    "category": "123",
                    "description": "Event for testing purposes",
                    "eventID": "1",
                    "locationID": "1",
                    "name": "jQuery",
                    "picturePath": "http://dochub.io/images/jquery_logo.png",
                    "subcategory": "SEIT",
                    "time": "12:00:00"
                }]
    
  • 您的数据源是在函数“dataInit”中初始化的,该函数在代码中的任何地方都没有显示。并且listview在视图的data init事件中初始化。因此,我假设列表在datasource之前初始化,导致数据不被绑定。 修复方法是,您可以将数据源保留在dataInit函数之外,如本小提琴中所示,该小提琴以您想要的方式使用您的代码:


  • 你确定你得到的是json吗?您发布的数据不是JSON。是的,我99.99999%确定我是JSON,这是解释我获取的数据的调试器。php脚本回显json编码的数据。您确定所生成的数据是数组吗?你能试着用你的数据做一个JSFIDLE吗?(它可以是固定编码的,这不要紧!)请准确地发布您从fiddler或您的浏览器开发工具捕获的数据。我们还需要确定.000001%的价格;)我已经修复了我的php并更新了问题以反映新的信息,有人有任何想法/帮助吗?我从服务器得到的响应是:{“eventID”:“1”,“name”:“test”,“time”:“12:00:00”,“category”:“category”:“subcategory”:“SEIT”,“description”:“用于测试的事件”,“locationID”:“1”,“picturePath”:“http:\/\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\函数,我试着让它自己关闭,但它仍然不起作用。这个提琴对你有帮助吗?你的解决方案与提琴有什么不同?是的,我试着精确地复制它,甚至在我放入php url的那一刻使用实际的提琴,而不是echo,这会导致永远的加载问题。我的php脚本如下所示。(它不适合放在评论框中)
    var app = new kendo.mobile.Application(document.body);        
    var dataSource = new kendo.data.DataSource({
    
        transport: {
            read: {
                //using jsfiddle echo service to simulate JSON endpoint
                url: "/echo/json/",
                dataType: "json",
                type: "POST",
                data: {
                    // /echo/json/ echoes the JSON which you pass as an argument
                    json: JSON.stringify([
                        {
                            "category": "123",
                            "description": "Event for testing purposes",
                            "eventID": "1",
                            "locationID": "1",
                            "name": "Kendo",
                            "picturePath": "https://si0.twimg.com/profile_images/1514396238/KendoUI-Figure.png",
                            "subcategory": "SEIT",
                            "time": "12:00:00"
                        } ,
                        {
                            "category": "123",
                            "description": "Event for testing purposes",
                            "eventID": "1",
                            "locationID": "1",
                            "name": "jQuery",
                            "picturePath": "http://dochub.io/images/jquery_logo.png",
                            "subcategory": "SEIT",
                            "time": "12:00:00"
                        }
                    ])
                }
            }
        }
    });
    
    function loadEventNames(){           
      $("#eventfeed").kendoMobileListView({
      dataSource: dataSource,
      template: $("#eventNameTemplate").html(),
      style:'inset'
     });
    }