Process returned JSON in webview
-
suppose i load a url in webview and there are some links in it , those links are actually to an API that returns JSON
my question : is there any to process that JSON before representing it
e.g. in my app : user make search : search go like this :
key term of search is used which return JSON . i process that and display itnow the links in json points to an API which returns JSON in return
currently on clicking the link it returns json and show it in webview
what i want to do is process that json too :Di have 2 gifs to make my point clear
https://postimg.org/image/lmfmubg81/
-
-
@Wieland i think something is wrong with ghostbin
try this : http://pastebin.com/TCpK9xuA
I have realized something that i think it would be better to move the search feature to C++ .
e.g. make search query -> send it to C++ code -> c++ make api call gets json-> process json and show resuls on webview .
Then repeat the step for the page
Can i repeatedly call/invoke / initalize webview ? . How will it affect the memory usage ?
-
In answer to my original question i did something like this
onUrlChanged: { console.log(searchwebview.url); test_json(); }
and i made this function to parse the returned JSON ( this function is not perfect yet )
function test_json() { var p_url = searchwebview.url var http = new XMLHttpRequest(); var json , parse , text , rev_id; http.onreadystatechange = function(){ if(http.readyState == 4 && http.status == 200) { json = http.responseText; parse = JSON.parse(json); rev_id = parse.parse.revid; console.log(rev_id); text = parse.parse.text["*"]; //console.log(text); // <-- STRIP ME (o.O) while(text.match(/'\/index.php/)){ text = text.replace(/'\/index.php/, "http://en.wikitolearn.org/index.php"); text = text.replace(/&/,"&"); text = text.replace(/MathShowImage&/, "MathShowImage&") text = text.replace(/mode=mathml'/, "mode=mathml\""); text = text.replace(/<meta class="mwe-math-fallback-image-inline" aria-hidden="true" style="background-image: url\(/ ,"<img style=\"background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.838ex;height: 2.843ex; \" src=\""); text = text.replace(/<meta class="mwe-math-fallback-image-display" aria-hidden="true" style="background-image: url\(/ ,"<img style=\"background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.838ex;height: 2.843ex; \" src=\""); text = text.replace(/&mode=mathml\"/ , "&mode=mathml>\""); text = styling + text; } console.log(text); // after strip :p . webview.loadHtml(text); } }; http.open('GET',p_url); http.send(); }