I'm trying to read a json url but JSON appearing some extra string before JSON start
JSON script is like:
throw 'allowIllegalResourceCall is false.';
{
"name":"mkyong",
"age":30,
"address":{
"streetAddress":"88 8nd Street",
"city":"New York"
},
"phoneNumber":[
{
"type":"home",
"number":"111 111-1111"
},
{
"type":"fax",
"number":"222 222-2222"
}
]
}
I'm trying to read this JSON using this below javascript:
<script>
$(document).ready(function() {
$('.button').click(function(){
var ur= "http://json_url";
alert(ur);
alert(JSON.stringify($.getJSON(ur)));
});
});
</script>
Is there any way to read this types of Json using java script/jQuery or ajax.
read this in some api doc
JSON Security String
GET requests are protected by including a security string on the line before the JSON text. The string generally looks like "throw 'allowIllegalResourceCall is false.';". To strip out this string, a regular expression should be used. For example, in python one could use:
json = re.sub(r"^throw.*;\s*","",json)
so you just need to replace the string with "" and use slashes around the regExp.
alert($.getJSON(ur).replace(/^throw.*;\s*/,"");
source : https://developers.jivesoftware.com/api/v3/cloud/rest/index.html