java - Extract elements between first and last occurrence of characters -


i have json string part of string -

this json {"name":"jim","age":12,"contactdetails": {"phone":"xxxxx"}} json ended 

in example , extract string starting first { , ending @ last }.

thanks answers. below code works suggested -

public class test {      public static void main(string[] args) {         // todo auto-generated method stub          string jsondata = "this json {\"name\":\"jim\",\"age\":12,\"contactdetails\": {\"phone\":\"xxxxx\"}} json ended";         system.out.println(jsondata.substring(jsondata.indexof("{"), jsondata.lastindexof("}") + 1));      }   } 

your program above may not work when have given nested json, purpose should take first index of { , last index of }, should using functions such indexof , lastindexof, because these give required indexes , can substring out of it... solved query, ask if need more clarification... happy help..


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -