我有以下类型的json数据,我希望使用java正则表达式从数据中提取标题
{
"Title": "nice television for the price",
"Author": "Jackie C",
"ReviewID": "R3LDJA7HU2Q0FS",
"Overall": "4.0",
"Content": "The television was a refurbished one, and for the price, quality of pictures, sound, i am enjoying it at this very moment. I'm glad that I made a good choice thus far without having any problems with the television. Thanks",
"Date": "April 13, 2014"
}
请告诉我从数据中提取标题将是正常的表达
答案 0 :(得分:3)
使用JSON解析器:
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class SOPlayground {
public static void main(String[] args) throws Exception {
String j = "{\n"
+ " \"Title\": \"nice television for the price\",\n"
+ " \"Author\": \"Jackie C\",\n"
+ " \"ReviewID\": \"R3LDJA7HU2Q0FS\",\n"
+ " \"Overall\": \"4.0\",\n"
+ " \"Content\": \"The television was a refurbished one, and for the price, quality of pictures, sound, i am enjoying it at this very moment. I'm glad that I made a good choice thus far without having any problems with the television. Thanks\",\n"
+ " \"Date\": \"April 13, 2014\"\n"
+ "}";
JSONParser p = new JSONParser();
JSONObject o = (JSONObject) p.parse(j);
System.out.println(o.get("Title"));
}
}
输出:
nice television for the price