jquery - Shodan JSON from python to javascript issue -
i'm working shodan api , i'm having issues while passing received json template (django).
this raw json structure:
{"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: utilize country_name", "latitude": 45.5, "os": "linux 2.6.x", "port": 443}]} and info construction pass template:
[{"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: utilize 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}] as can see there lot of special chars within wich mess conversion. issue "hostnames" kid wich list of elements (if exist elements)...
anyone knows how handle json file in js/jquery right format? regards.
edit: checking output javascript , special chars passed django view template converted html code , \r\n disapear causing parsing error:
i compared both json files with: http://json.parser.online.fr/
and json received shodan api , manipulated in view works fine not json pased template.
i found problem, said in question when pass json view template django converts characters used in javascript strings.
the solution add together escapejs tag variable in template:
{{ json|escapejs}}
here can find docs: https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#escapejs
javascript jquery python django json
No comments:
Post a Comment