org.json - Javascript handling .json file's lines -
how json file divided lines using java script.as done in python using readlines(). have uploaded .json file , need find keywords in , display lines in keywords found line number. example of json file given below:
{ "data": [], "numfound": 0, "context": { "rows": "50", "from": "2014-01-11t17:48:40.000z", "until": "2014-01-11t17:48:40.000z", "start": 0, "query": "( json.system_version:3.4.42 json.id.discoveryserveruri:\"svcs.myharmony.com\" json.event_level:error json.crashcode:syncabort )", "order": "desc" } }
i guess want load json file @ once. can this:
function loadjson(callback) { var xobj = new xmlhttprequest(); xobj.overridemimetype("application/json"); //if want synchronous, replace false xobj.open('get', 'json_file.json', true); xobj.onreadystatechange = function () { if (xobj.readystate == 4 && xobj.status == "200") { callback(xobj.responsetext); } }; xobj.send(null); }
and then,
readjson(function(response) { // "read" json var data = json.parse(response); //do whatever want });
hope helps.
Comments
Post a Comment