我正在使用Shodan API,並在將接收到的JSON傳遞給模板(django)時遇到問題。Shodan JSON從python到javascript問題
這是原始JSON結構:
{"matches": [{"city": "Montreal", "updated": "02.02.2013", "ip": "24.48.3.143", "longitude": -73.5833, "data": "HTTP/1.0 200 OK\r\nDate: Sat, 02 Feb 2013 00:41:53 GMT\r\nServer: Apache/1.3.42 (Unix) mod_auth_pam/1.1.1 DAV/1.0.3 mod_ssl/2.8.31 OpenSSL/0.9.8g\r\nSet-Cookie: iomega=174.79.246.153.26931359765713476; path=/\r\nCache-Control: no-cache\r\nConnection: close\r\nTransfer-Encoding: chunked\r\nContent-Type: text/html; charset=utf-8\r\n\r\n", "country_name": "Canada", "hostnames": [], "country_code": "CA", "country": "DEPRECATED: use country_name", "latitude": 45.5, "os": "Linux 2.6.x", "port": 443}]}
這是數據結構我傳遞給模板:
[{"city": "Montreal", "updated": "02.02.2013", "os": "Linux 2.6.x", "ip": "24.48.3.143", "longitude": -73.5833, "latitude": 45.5, "hostnames": [], "country_code": "CA", "country": "DEPRECATED: use country_name", "country_name": "Canada", "data": "HTTP/1.0 200 OK\r\nDate: Sat, 02 Feb 2013 00:41:53 GMT\r\nServer: Apache/1.3.42 (Unix) mod_auth_pam/1.1.1 DAV/1.0.3 mod_ssl/2.8.31 OpenSSL/0.9.8g\r\nSet-Cookie: iomega=174.79.246.153.26931359765713476; path=/\r\nCache-Control: no-cache\r\nConnection: close\r\nTransfer-Encoding: chunked\r\nContent-Type: text/html; charset=utf-8\r\n\r\n", "port": 443}]
正如你可以看到有很多裏面特殊字符的這些亂七八糟的轉換。另一個問題是與「主機名」孩子這是一個元素列表(如果存在的元素)...
任何人都知道如何處理js/jquery這個正確的格式的JSON文件? 此致敬禮。
編輯:我檢查由我的JavaScript和Django的視圖模板傳遞的特殊字符輸出轉換爲HTML代碼和\ r \ n disapear導致解析錯誤:
我比較了兩個JSON文件與:http://json.parser.online.fr/
而jodson從操作API接收和操縱在視圖中工作正常,但不是JSON的模板。