Poor description,here is the cpp code


#1

string indent(int i){
string s="";
int j=0;
while(j<i){
s=s+"\t";
j++;
}
return s;
}
vector Solution::prettyJSON(string A) {
int k=0;
vectorv;
for(int i=0;i<A.size();i++){
string s=indent(k);
while(A[i]!=’,’&&A[i]!=’{’&&A[i]!=’[’&&A[i]!=’}’&&A[i]!=’]’&&i<A.size()){
s=s+A[i];
i++;
}
if(i==A.size()){
if(s.size()>0){
v.push_back(s);
}

        break;
    }
    if(A[i]==','){
        s=s+A[i];
        v.push_back(s);
    }else if(A[i]=='{'||A[i]=='['){
        if(s.size()==k){
            s.clear();
        }
        if(s.size()>0){
          v.push_back(s);  
        }
        string t=indent(k)+A[i];
        //cout<<t<<"*";
        v.push_back(t);
        k++;
    }
    else if(A[i]=='}'||A[i]==']'){
        
        if(s.size()==k){
            s.clear();
        }
        k--;
        if(s.size()>0){
             v.push_back(s);
        }
        string t=indent(k)+A[i];
        if(i+1<A.size()&&A[i+1]==','){
            i++;
            t=t+A[i];
        }
        v.push_back(t);
    }
}
return v;

}