0
我有這樣的代碼:我如何獲得價值從轉換後的字符串
def converted = "{\"" + resp.data.toString()
.replaceAll('=','\":\"')
.replaceAll('&','\",\"') + "\"}"
它返回有效的JSON格式雖然我:
"response=3&responsetext=Duplicate transaction REFID:3154223053&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=auth&response_code=300"
我嘗試使用這個代碼轉換成JSON格式想要從該字符串中獲得特定的值我試過:
println converted.responsetext.toString()
它有一個錯誤,說
沒有這樣的屬性:responseText的類:java.lang.String中
...你有一個字符串。當你將正確的字符連接在一起時,它不是某種神奇的JSON類,它只是一個帶有JSON格式明文的字符串。 –
有無論如何,我可以得到該json格式字符串的具體值 – pauleng
是的,請參閱答案部分。 –