Example usage for org.json JSONWriter toString

List of usage examples for org.json JSONWriter toString

Introduction

In this page you can find the example usage for org.json JSONWriter toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:util.CacheUtil.java

private static String genJsonCustomV127(CustomAd customAd) throws JSONException {
    JSONWriter jsonWriter = new JSONStringer();

    int launch_type;

    String s_link_type = customAd.getLinkType();
    int link_type = -1;
    try {/* w  w  w .j  ava2 s  .  co m*/
        link_type = Integer.parseInt(s_link_type);
    } catch (NumberFormatException e) {
        link_type = 1;
    }

    if (customAd.getLaunchType().equals("")) {
        if (link_type == 2) {
            launch_type = 1;
        } else {
            launch_type = 2;
        }
    } else {
        String s_launch_type = customAd.getLaunchType();
        launch_type = Integer.parseInt(s_launch_type);
    }

    jsonWriter = jsonWriter.object().key("img_url").value(customAd.getImageLink()).key("redirect_url")
            .value(customAd.getLink()).key("metrics_url")
            .value("http://" + AdWhirlUtil.SERVER + "/exclick.php?nid=" + customAd.getNid()
                    + "&appid=$aid&type=9&appver=200")
            .key("metrics_url2").value("").key("ad_type").value(customAd.getType()).key("ad_text")
            .value(customAd.getDescription()).key("link_type").value(link_type).key("launch_type")
            .value(launch_type).key("subtext").value("").key("webview_animation_type").value(4).endObject();

    return jsonWriter.toString();
}