java - Match string between multiple brackets -


i have long json string. filtrate , data between first bracket. problem is, have many other brackets therefore regex pattern not working properly.

here json string:

    string jsondata = "["     +"{"       +  "test: 63453645"         +"date: 2016-07-17"        "{"         + "id:534534"         +"}"       + "blank : null"       + "flags : null"      + "}"     +"{"       +  "test: 543564236"         +"date: 2014-07-17"         +"{"         + "id:6532465"         +"}"       + "blank : null"       + "flags : null"     + "}"     +"]";      pattern = "\\{[^{}]*\\}";     pr = pattern.compile(pattern);       math = pr.matcher(jsondata);     if (math.find()) {         system.out.println(math.group());     }     else         system.out.println("nomatch"); 

the problem pattern have prints out first } after id:, want end @ last } after flags: null.

and want print first match, i.e not string after because start , end same character, , why have if statement instead of while loop.

any suggestions? thank you!

regex multiple brackets seems difficult task. can match last string instead? starting { flags : null?

like said in comment, make use of json-simple. great tutorial, decoding.

would like:

jsonobject obj = jsonvalue.parse(jsondata); obj.get("test"); 

ps. see errors in json data, make use of jsonlint verify if json formatted correctly...


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -