一个截取字符串的例子

截取如下一个字符串

{

  "code": "0000",

  "message": "",

  "data": {

    "payRecordId": "1",

"payUrlOrData":"alipay_sdk=alipay-sdk-java-3.1.0&app_id=2016072900113812&biz_content=%7B%22body%22%3A%22%E9%87%91%E5%A4%A7%E5%B8%88%E6%94%AF%E4%BB%98%E5%AE%9DAPP%E6%94%AF%E4%BB%98%22%2C%22out_trade_no%22%3A%22****20%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22subject%22%3A%22%E9%87%91%E5%A4%A7%E5%B8%88%E6%94%AF%E4%BB%98%22%2C%22timeout_express%22%3A%2230m%22%2C%22total_amount%22%3A%225%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay&notify_url=http%3A%2F%2F192.168.153.116%3A19030%2Fpay%2FnotifyByAlipay&sign=sbY%2FKCVLNzz3sTTwXOVFhxDZ5U91elOwlvVKt4o0J6vZan9WBnkCNgPleyvtrchSF2hySqQYycAbE0fVCB3p7Uj0s%2BrB%2FKQUSfeDApsdjJjPEq4a%2FTTStoTJAK784l0q%2Bzc1Zn7pF1U7ALb6Jqv7AtSzZa17YkHFKtDmHr1c4GU%3D&sign_type=RSA2&timestamp=2018-06-26+14%3A38%3A54&version=1.0"

  },

  "success": true

}

 

val str = data.payUrlOrData.split("&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
for (item in str){
    if (item.substring(0,6) == "app_id"){
        val appId = item.substring(item.indexOf("="),item.length)
        Log.e("mls","appId的值>>>" + appId)
    }
    if (item.substring(0,10) == "alipay_sdk"){
        val aliPaySdk = item.substring(item.indexOf("="),item.length)
        Log.e("mls","aliPaySdk的值>>>" + aliPaySdk)
    }
    if (item.substring(0,11) == "biz_content"){
        val bizContent = item.substring(item.indexOf("="),item.length)
        Log.e("mls","biz_content的值>>>" + bizContent)
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值