byte Array to Json - Android File Input Output

Android examples for File Input Output:Json

Description

byte Array to Json

Demo Code


//package com.java2s;

public class Main {
    static String byteArray2Json(final byte[] array) {
        if (array.length == 0) {
            return "[]";
        }/*from  ww w .jav  a  2  s  .c o m*/
        final StringBuilder sb = new StringBuilder(array.length << 4);
        sb.append('[');
        for (final byte o : array) {
            sb.append(Byte.toString(o));
            sb.append(',');
        }
        // set last ',' to ']':
        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }
}

Related Tutorials