c# - Extract json data from string using regex -
i have data string below:
.... data=[{"caseno":1863,"casenumber":"rd14051315","imageformat":"jpeg","shiftid":241,"city":"riyadh","imagetypeid":2,"userid":20}] --5qf7xjyp8snivhqycpkmdjs-zg0qde4oqiyig content-disposition: form-data .....
i want fetch json data above string. how can use regex find part of string? tried finding indexof("data=[") , indexof("}]") not working fine , proper way do.
i'm not entirely there isn't better way this, following regex string should data need:
// define regular expression, including "data=" // put latter part (the part want) in own group regex regex = new regex( @"data=(\[{.*}\])", regexoptions.multiline ); // run regular expression on input string match match = regex.match(input); // now, if we've got match, grab first group if (match.success) { // our json string string jsonstring = match.groups[1].value; // whatever need (e.g. de-serialise json) ... } }
Comments
Post a Comment