Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}
- <?php
- $input = '{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}';
- print_r(json_decode($input, true));
- ?>
- Array
- (
- [chg] => -0.71
- [vol] => 40700
- [time] => 11.08.2011 12:29:09
- [high] => 1.417
- [low] => 1.360
- [last] => 1.400
- [pcl] => 1.410
- [turnover] => 56,560.25
- )
- :"([^"].*?)"
- /:"([^"].*?)"/
- import java.util.regex.*;
- String test='{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}'
- // Create a pattern to match breaks
- Pattern p = Pattern.compile(':"([^"]*)"');
- // Split input with the pattern
- // Run some matches
- Matcher m = p.matcher(test);
- while (m.find())
- System.out.println("Found comment: "+m.group().replace('"','').replace(":",""));
- Found comment: -0.71
- Found comment: 40700
- Found comment: 11.08.2011 12:29:09
- Found comment: 1.417
- Found comment: 1.360
- Found comment: 1.400
- Found comment: 1.410
- Found comment: 56,560.25
- <?php
- $subject = '{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}';
- $pattern = '/(?<=:")[^"]*/';
- preg_match_all($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
- print_r($matches);
- ?>
- Array ( [0] => Array ( [0] => Array ( [0] => -0.71 [1] => 8 ) [1] => Array ( [0] => 40700 [1] => 22 ) [2] => Array ( [0] => 11.08.2011 12:29:09 [1] => 37 ) [3] => Array ( [0] => 1.417 [1] => 66 ) [4] => Array ( [0] => 1.360 [1] => 80 ) [5] => Array ( [0] => 1.400 [1] => 95 ) [6] => Array ( [0] => 1.410 [1] => 109 ) [7] => Array ( [0] => 56,560.25 [1] => 128 ) ) )
Add Comment
Please, Sign In to add comment