Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

public class Main {
    public static String Json2Str(Map<String, Object> info) {
        String result = "";
        if (info != null) {
            try {
                JSONObject json = new JSONObject();
                for (Map.Entry<String, Object> e : info.entrySet()) {
                    String key = e.getKey();
                    if (json.isNull(key)) {
                        json.put(key, null);
                    } else {
                        json.put(key, json.get(key));
                    }
                }
                result = json.toString();
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        return result;
    }
}