Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Process returned JSON in webview

Process returned JSON in webview

Scheduled Pinned Locked Moved General and Desktop
jsonwebviewqt quickqml
4 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qjay
    wrote on 18 Jul 2016, 16:51 last edited by Qjay
    #1

    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 it

    now 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 :D

    i have 2 gifs to make my point clear

    https://postimg.org/image/lmfmubg81/

    https://postimg.org/image/9y1ehs43l/

    code : https://ghostbin.com/paste/cfsaq

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 20 Jul 2016, 20:13 last edited by
      #2

      @Qjay said:

      code : https://ghostbin.com/paste/cfsaq

      Can't access it

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qjay
        wrote on 21 Jul 2016, 15:53 last edited by
        #3

        @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 ?

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qjay
          wrote on 21 Jul 2016, 16:11 last edited by
          #4

          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(/&#39;\/index.php/)){
                                 text = text.replace(/&#39;\/index.php/, "http://en.wikitolearn.org/index.php");
                                 text = text.replace(/&amp;/,"&");
                                 text = text.replace(/MathShowImage&amp;/, "MathShowImage&")
                                 text = text.replace(/mode=mathml&#39;/, "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(/&amp;mode=mathml\"/ , "&mode=mathml>\"");
                                 text = styling + text;
          
                                 }
                                 console.log(text); // after strip :p .
          
                                 webview.loadHtml(text);
                             }
                         };
                         http.open('GET',p_url);
                         http.send();
          
          
          
              }
          
          1 Reply Last reply
          0

          3/4

          21 Jul 2016, 15:53

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved