0

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

7
  • 9
    Do not use regex. Use a JSON parser. Commented Apr 14, 2015 at 7:09
  • I suggest you take a look at the org.json library (import org.json.*) rather than using regex. Commented Apr 14, 2015 at 7:10
  • Thanx for quick reply i alredy tried with json parser but i got left '[ ' error Commented Apr 14, 2015 at 7:10
  • you can also use GSON for the same. Commented Apr 14, 2015 at 7:11
  • is there is any gui based tool available which can parse my json data easily,,,actually i want extract title from json file,,, Commented Apr 14, 2015 at 7:15

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.