簡體   English   中英

使用Java正則表達式解析JSON數據

[英]Parse json data using java regular expression

我有以下類型的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"
}

請告訴我從數據中提取標題,這將是正規表達式

使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM