简体   繁体   中英

Parse json data using java regular expression

I have following type of json data and I want extract title from data using java regular expression

{
    "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"
}

please tell me for extract title from data what will be regular expresion

Use a JSON parser:

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"));
    }
}

Output:

nice television for the price

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM