Android Open Source - inspectable J S O N Util






From Project

Back to project page inspectable.

License

The source code is released under:

Apache License

If you think the Android project inspectable listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.hanqin.apps.inspect.util;
/*from  w  ww  .  j  a  v a 2s .  co m*/
import android.database.Cursor;

import java.util.List;

public class JSONUtil {

    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("',");
        }
        builder.deleteCharAt(builder.length() - 1);
        builder.append("]");
        builder.append("}");
        return builder.toString();
    }

    public static String cursorToJson(Cursor cursor) {
        StringBuilder builder = new StringBuilder();
        builder.append("{\"result\": [");
        boolean hasResult = false;
        while (cursor.moveToNext()) {
            hasResult = true;
            int columnCount = cursor.getColumnCount();

            builder.append("{");
            for (int i = 0; i < columnCount; i++) {
                builder.append(String.format("\"%s\": \"%s\"", cursor.getColumnName(i), cursor.getString(i))).append(",");
            }
            builder.deleteCharAt(builder.length() - 1);
            builder.append("},");
        }
        if (hasResult) {
            builder.deleteCharAt(builder.length() - 1);
        }
        builder.append("]}");
        cursor.close();
        return builder.toString();
    }
}




Java Source Code List

fi.iki.elonen.NanoHTTPD.java
me.hanqin.apps.inspect.Inspectable.java
me.hanqin.apps.inspect.PreferenceConfigure.java
me.hanqin.apps.inspect.handlers.BaseHandler.java
me.hanqin.apps.inspect.handlers.DatabaseHandler.java
me.hanqin.apps.inspect.server.DefaultRequestDispatcher.java
me.hanqin.apps.inspect.server.HttpServer.java
me.hanqin.apps.inspect.util.JSONUtil.java