0

I used WebBrowser control inside a C# Winform application. Inside the webpage.html I put some javascript code like this:

function markerMoved() {
    var lat = ; // Get lat
    var lng = ; // Get lng
    var addrStr = reverseGeocoding(lat, lng);
    if(isJsonFormat(addrStr)) {
        var addrObj = JSON.parse(addrStr);
        var fullAddr = addrObj.fullAddr;
        alert(fullAddr);
    }
}

function isJsonFormat(str)
    try{
        JSON.parse(str);
    }catch(e){
        return false;
    }

    return true;
}

When I opened the webpage.html by browsers (e.g. Firefox) it worked perfectly but when I launched the Winform application the isJsonFormat(addrStr) always returned false. Why did it happen? How could I solve this?

duong_dajgja
  • 4,196
  • 1
  • 38
  • 65
  • 1. Try `console.log(e)` (I don't know how you would do it using WinForm). Just display the data. 2. Try the first solution of [this post](http://stackoverflow.com/questions/3710204/how-to-check-if-a-string-is-a-valid-json-string-in-javascript-without-using-try) (Replace the `text` variable with your variable. – nicovank Nov 09 '16 at 06:29
  • @nicovank the `isJsonFormat()` that I used is actually the highest up-vote answer in the link you suggested. – duong_dajgja Nov 09 '16 at 06:33
  • I know but still try the other one using the regexp -- or log the error so that we know what's wrong – nicovank Nov 09 '16 at 06:36

0 Answers0