gpt4 book ai didi

javascript - Android webView.loadUrl 带引号

转载 作者:太空宇宙 更新时间:2023-11-04 13:23:50 25 4
gpt4 key购买 nike

使用下面的java和javascript代码;我在这一行 document.getElementById('txtCardSwipePOS').value = "[SWIPED_CARD]"; 上收到错误。如果我将 [SWIPED_CARD] 周围的双引号更改为单引号,它就可以工作。

但是如果我的字符串中有单引号,它就不起作用。理想情况下,我希望在 "[SWIPED_CARD]" 周围加上双引号,以便 json 编码正常工作;但似乎通过带双引号的 url 加载 javascript 不起作用。有办法解决这个问题吗?

    String creditCardSwipe = new String (cardData);

creditCardSwipe = StoreWebActivity.jsonString(creditCardSwipe);
String javascriptCode = "";
try {
javascriptCode = StoreWebActivity.convertStreamToString(getResources().openRawResource(R.raw.credit_card_swipe));
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int API = android.os.Build.VERSION.SDK_INT;
javascriptCode = javascriptCode.replace("[SWIPED_CARD]", creditCardSwipe);

//old way of injecting javascript
if (API < 19)
{
webView.loadUrl("javascript:"+javascriptCode);
}
else //Android 19 or above
{
webView.evaluateJavascript(javascriptCode,null);
}

//Sometimes swipes can be detected as valid, but in reality aren't so request swipe again
myUniMagReader.startSwipeCard();
isWaitingForSwipe = true;

R.raw.credit_card_swipe(上面加载了 JS)

if (document.getElementById('txtCardSwipePOS'))
{
document.getElementById('txtCardSwipePOS').value = "[SWIPED_CARD]";
}

if (document.getElementById('divProgressOverlay'))
{
document.getElementById('divProgressOverlay').style.display = '';
}

if (document.getElementById('imgProgress'))
{
ProgressImg = document.getElementById('imgProgress');
setTimeout('ProgressImg.src = ProgressImg.src', 0);
}

if (document.getElementById('frmCheckout'))
{
//Need to use setTimeout for form submission so loading indicators have time to display (this is for Android)
setTimeout(function()
{
document.getElementById('frmCheckout').submit();
},0);
}

最佳答案

问题是,当转换为 json 时,它会自动添加双引号。因此,从 js 文件中删除引号即可解决此问题。

关于javascript - Android webView.loadUrl 带引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32833572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com