android - Java - Date Pattern matching -
i new java. please me. have problem json response below:
{"getresult":"{ \"isdate\": [ { \"code\": \"200\" }, { \"message\": \"fetched successfully\" }, { \"id\": \"722c8190c\", \"name\": \"recruitment\", \"path\": \"url\", \"date\": \"14 may, 2013\" }, ]}"} its malformed json object. so, using matching pattern data of name, path , date , getting name , path below:
matcher matchername = pattern.compile("\\\\\"name\\\\\":\\s\\\\\"[^,}\\]]+\\\\\"").matcher(name); matcher matcherpath = pattern.compile("\\\\\"path\\\\\":\\s\\\\\"^[^,}\\]]+\\\\\"").matcher(path); so, above lines, able path , name. so, please how date well. format of date 14 may, 2013. please me.
matcher same in question:
matcher matcherdate = pattern.compile("\\\\\"date\\\\\":\\s\\\\\"([^\\\\]*)\\\\\"").matcher(brokenjson); while (matcherdate.find()) { system.out.println(matcherdate.group(1)); } then can parse date using simpledateformat
update. full code read brokenjson file , parse it:
string brokenjson = files.tostring(new file("1.dat"), charset.defaultcharset()); matcher matcherdate = pattern.compile("\\\\\"date\\\\\":\\s\\\\\"([^\\\\]*)\\\\\"").matcher(brokenjson); while (matcherdate.find()) { system.out.println(matcherdate.group(1)); }
Comments
Post a Comment