Java Json Create toLocalJson(Object value, int depth)

Here you can find the source of toLocalJson(Object value, int depth)

Description

to Local Json

License

Apache License

Declaration

private static String toLocalJson(Object value, int depth) 

Method Source Code

//package com.java2s;
/**/*w  ww  .  j  av  a2 s  . c  om*/
 * Copyright (c) 2011-2012, James Zhan ?? (jfinal@126.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Map;

public class Main {

    private static String toLocalJson(Object value, int depth) {
        String[] xAxisCategories = new String[] { "2013-01", "2013-02", "2013-03", "2013-04", "2013-05", "2013-06",
                "2013-07", "2013-08", "2013-09", "2013-10", "2013-11", "2013-12" };
        StringBuilder sb = new StringBuilder();
        String _str = "";
        if (value == null || (depth--) <= 0) {
            return "null";
        }
        if (value instanceof Map) {
            Map _mapResult = (Map) value;
            sb.append("data:[");

            for (String xAxis : xAxisCategories) {
                if (_mapResult.containsKey(xAxis)) {
                    sb.append(_mapResult.get(xAxis)).append(",");
                } else {
                    sb.append("null,");
                }
            }

            _str = sb.toString().substring(0, sb.toString().length() - 1);
            _str = _str + "]";
        }
        return _str;
    }
}

Related

  1. toJSON(Map map)
  2. toJson(Object object)
  3. toJson(Object object, String dateFormat)
  4. toJsonString(Map map)
  5. toList(String json, Class clz)