Re: [問題] 字串如何轉換成json的資料
也可以利用正規表示式來做。
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
public static void main(String[] args) {
Pattern patt = Pattern.compile("([a-zA-Z0-9]+)=([a-zA-Z0-9]+)");
String input = "pa1=xxx&pa2=yyy&pa3=ttt";
Matcher m = patt.matcher(input);
while (m.find()) {
System.out.println(
String.format("k[%s] v[%s]", m.group(1), m.group(2)));
}
}
}
PS. value 的部分再加個 URLDeocder 來解析比較好
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.165.131
討論串 (同標題文章)
完整討論串 (本文為第 2 之 3 篇):