I need to run a function matchFound() if a string is found in an external json file.
This is what I have so far:
function init(){
$.ajax({
type: "GET",
url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&callback=?&q=http://www.domain.com/feed.rss",
dataType: "json",
success: parseData
});
}
function parseData(data){
var string_to_find = "Hello World!";
// look into the data and match the string
}
function matchFound(str, string_to_find){
alert('Match found in string - '+ str +'\r\n While looking for the string- '+ string_to_find);
return true;
}
function matchNotFound(){
alert('No Match found!');
}
But I don't know how to parse the Json data and search for a string.
I have this for XML (thanks @Ohgodwhy) but not sure how to translate for json
function parseXml(xml){
var string_to_find = "Hello World!";
$(xml).find('title').each(function(){
var str = $(this).text();
if(str.indexOf(string_to_find) > -1){
if(matchFound(str, string_to_find)){
return false;
}
}
});
}
The search location within the variables is: responceData > feed > entries > [0] or 1 or [2] etc > contentSnippet
I only need to match the first 10 characters.
If a match is found then run the funciton matchFound() or if not found run the function matchNotFound()
Any help with this is very much appreciated.
C
