簡體   English   中英

如何從WebView獲取URL中存在的值並將其附加到另一個URL並在android中加載?

[英]How to fetch the values present in a url from a webview and append it to another url and load in android?

考慮網址:www.xyz.com/buy/thankyou/handlers/display.html?ie=UTF8&asins=B00F0G8K&orderId=404-35644-70307&purchaseId=404-2849-9658作為第一網址。 第二個網址是:sndbx.abc.com/mob#?path=confirmOrder&oid=&pid =&asins =。 在這里,應將第一個網址中的orderid(multiple),purchaseId和asins的值填充到第二個網址中,即,第二個網址應為sndbx.abc.com/mob#?path=confirmOrder&asins=B00F8K&oid=40444-7037&pid= 4089-958。

您可以使用簡單的URL拆分器,也可以將其創建為靜態幫助器或其他內容。 例如:

String url1 =..., url2=...;
String[] url1splitted = url1.split("&");
for(String pair:url1splitted){
    if(pair.contains("=") && pair.length()>=3 && getCount(pair, '=')=1){
        String param = pair.split("=")[0];
        String value = pair.split("=")[1];
        // add to HashMap, format another url or whatever...
    }
}

//getCount method
private int getCount(String pair, Char lookingFor){
    int counter = 0;
    for(int i=0; i<pair.length(); i++)
        if( pair.charAt(i) == lookingFor )
            counter++;
    return counter;
}

replaceAll("[&][a-zA-Z0-9._%+-]{1,}[=]","")將替換第二個url中沒有值的所有鍵。

URL_1.split("?")[1]將為您提供所有鍵值對,因此。

URL_2= URL_2.replaceAll("[&][a-zA-Z0-9._%+-]{1,}[=]","").concat(URL_1.split("?")[1] );

會做有需要的。 希望這有助於加油:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM