java 正则表达式截取 json 对象的键值


package test.main;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test1 {

	public static void main(String[] args) {
		String parem = "{\"param\":{\"song_id\":\"10023423001\"},\"song_id\":\"132430001\"  }";
		// 匹配规则是当avatar是{}包装的对象

		String result = "";
		Pattern mPAvatar = Pattern.compile("\"param\":\\{([^\\}]*)\\}");
		Matcher mMAvatar = mPAvatar.matcher(parem);
		while (mMAvatar.find()) {// 如果找到 开始替换
			result = mMAvatar.group();
		}
		System.out.println(result);
	}
}
参数:{"param":{"song_id":"10023423001"},"song_id":"132430001"  }
打印  :"param":{"song_id":"10023423001"}



参考:http://blog.csdn.net/Card361401376/article/details/51026649

你可能感兴趣的:(json)