簡體   English   中英

解析json中發生意外錯誤

[英]Unexpected error in parsing json

使用此處給出的教程,我正在制作一個應用程序,以從URL提取json數據並顯示它。 我正在使用此代碼來調用URL並進行解析。

{
                    xtype: 'nestedlist',
                    title: 'Blog',
                    iconCls: 'star',
                    cls: 'blog',
                    displayField: 'title',

                    store: {
                        type: 'tree',

                        fields: ['uuid', 'display'


                        ],

                        root: {
                            leaf: false
                        },

                        proxy: {
                            type: 'scripttag',
                            url: 'http://localhost:8081/openmrs-standalone/ws/rest/v1/location',
                            reader: {
                                type: 'json',
                                rootProperty: 'results'
                            }
                        },

                    },

                },

在控制台中,我以表格形式獲得響應

{
    "results": [
        {
            "uuid": "c0937f0c-1691-11df-97a5-7038c432aabf",
            "display": "Chulaimbo",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/c0937f0c-1691-11df-97a5-7038c432aabf",
                    "rel": "self"
                }
            ]
        },
        {
            "uuid": "c0937d4f-1691-11df-97a5-7038c432aabf",
            "display": "Mosoriot Hospital",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/c0937d4f-1691-11df-97a5-7038c432aabf",
                    "rel": "self"
                }
            ]
        },
        {
            "uuid": "8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
            "display": "Unknown Location",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
                    "rel": "self"
                }
            ]
        }


    ]
}

但顯示錯誤 在此處輸入圖片說明 “位置”是服務的名稱。

控制台認為您正在嘗試將JSON作為代碼執行。 因此,在第一個{ ,它需要指令。 沒有數據。 嘗試在整個內容中加上括號:

{ myfield: 1, anotherfield: 2 } (ERROR)

({ myfield: 1, anotherfield: 2 }) (SUCCESS)

這樣可以解決問題。

我已經使用其他方法完成了。 我使用代理類型“ rest”並在同一服務器和端口上運行OpenMRS和我的應用程序,否則我的OpenMRS實例將不允許跨域調用。 這個問題的問題是使用type作為“ scripttag”,我仍然不知道它是什么問題。使用“ rest”可以解決它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM