list To Json String - Android File Input Output

Android examples for File Input Output:Json String

Description

list To Json String

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    public static String listToJson(String key, List<String> values) {
        StringBuilder builder = new StringBuilder();
        builder.append("{");
        builder.append("'" + key + "': [");
        for (String database : values) {
            builder.append("'").append(database).append("',");
        }/*from   w ww.jav  a2  s.  c  o  m*/
        builder.deleteCharAt(builder.length() - 1);
        builder.append("]");
        builder.append("}");
        return builder.toString();
    }
}

Related Tutorials