Java String Split splitJsonObjects(String string)

Here you can find the source of splitJsonObjects(String string)

Description

split Json Objects

License

Apache License

Declaration

protected static List<String> splitJsonObjects(String string) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    protected static List<String> splitJsonObjects(String string) {
        List<String> jsonObjects = new ArrayList<String>();
        int brackets = 0;
        int start = 0;

        for (int i = 0; i < string.length(); i++) {
            switch (string.charAt(i)) {
            case '{':
                brackets++;//from   w  ww. j  a v  a  2 s  .  c  o m
                if (brackets == 1)
                    start = i;
                break;
            case '}':
                brackets--;
                if (brackets < 0) {
                    jsonObjects.clear(); // we started in the middle of a json
                                         // object
                    brackets = 0;
                } else if (brackets == 0) {
                    jsonObjects.add(string.substring(start, i + 1));
                }
                break;
            default:
                break;
            }
        }
        return jsonObjects;
    }
}

Related

  1. splitIntegerFromString(String str)
  2. splitIntegerPerDigit(int i)
  3. splitIntoPackages(String stmt)
  4. splitIntoPairs(String subDirName)
  5. splitInts(String str)
  6. splitJsonObjects(String value)
  7. splitLargeStringIfNecessary(String s)
  8. splitList(String list)
  9. splitList(String string)