Example usage for org.json JSONObject JSONObject

List of usage examples for org.json JSONObject JSONObject

Introduction

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

Prototype

public JSONObject() 

Source Link

Document

Construct an empty JSONObject.

Usage

From source file:com.saggezza.litrackerlite.track.TrackerC.java

public static void main(String[] args) throws IOException, JSONException, URISyntaxException {
    ///// Setup//from  w ww.  j a  va  2 s  .co  m

    ///// CONFIGURATIONS
    TrackerC.debug = false;
    TrackerC.track = false;
    TrackerC.singleVar = false;

    ///// EmitterC
    Emitter emitter = new Emitter("localhost:80", "JavaPlow/urlinfo");

    ///// REGULAR TRACKER
    Tracker t1 = new TrackerC(emitter, "Tracker Test", "JavaPlow", "com.com.saggezza");
    //        t1.setUserID("User1");
    t1.setLanguage("eng");
    t1.setPlatform("pc");
    t1.setScreenResolution(1260, 1080);
    String context = "{'Zone':'USA', 'Phone':'Droid', 'Time':'2pm'}";

    ///// E COMMERCE TEST
    //        Map<String,String> items = new HashMap<String, String>();
    //        items.put("sku", "SKUVAL"); items.put("quantity","2"); items.put("price","19.99");
    //        List<Map<String,String>> lst = new LinkedList<Map<String, String>>();
    //        lst.add(items);

    ///// GENERICS
    //        GenericTracker t2 = new TrackerC(emitter, "GenericTracker Test", "JavaPlow", "com.com.saggezza");
    //        t2.setLanguage("English");
    //        t2.setPlatform("pc");
    //        t2.setScreenResolution(1200, 1080);

    ///// GENERIC MAP
    //        Map<String, Object> dict = new LinkedHashMap<String, Object>();
    //
    //        dict.put("Username", System.getProperty("user.name"));
    //        dict.put("OperatingSystem", System.getProperty("os.name"));
    //        dict.put("OS_Version", System.getProperty("os.version"));
    //        dict.put("JRE_Version", System.getProperty("java.version"));

    /////TRACK TEST
    for (int i = 0; i < 1; i++) {
        //            dict.put("Iteration", i);
        //            System.out.println(dict.toString() + "\n" + t2.getPayload().toString());
        //            t2.setupTrack("Kevin");
        //            t2.trackGenericEvent("Lube Insights", "Data Loop", dict, context);
        t1.setupTrack("Kevin", new JSONObject());
        long s1 = System.currentTimeMillis();
        t1.trackPageView("saggezza.com", "Home Page", "KevinReferred", context);
        long e1 = System.currentTimeMillis() - s1;
        long s2 = System.currentTimeMillis();
        t1.trackPageView("saggezza.com", "Home Page", "KevinReferred", context);
        t1.terminateExecutor();
        long e2 = System.currentTimeMillis() - s2;
        System.out.print(e1 + " " + e2);
        //            t1.trackEcommerceTransactionItem("IT1023", "SKUVAL", 29.99, 2, "boots", "Shoes","USD",null,null);
        //            t1.trackEcommerceTransaction("OID", 19.99, "Kohls", 2.50, 1.99, "Chagrin", "OH", "USA", "USD", lst, context);
    }
}

From source file:com.codebutler.farebot.keys.ClassicSectorKey.java

public JSONObject toJSON() {
    try {//from  w ww  . j  a v  a2 s  .c o  m
        JSONObject json = new JSONObject();
        json.put(TYPE, mType);
        json.put(KEY, Utils.getHexString(mKey));
        return json;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.basetechnology.s0.agentserver.field.MoneyField.java

public JSONObject toJson() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("type", "money");
    if (symbol.name != null)
        json.put("name", symbol.name);
    if (label != null)
        json.put("label", label);
    if (description != null)
        json.put("description", description);
    if (defaultValue != 0)
        json.put("default_value", defaultValue);
    if (minValue != 0)
        json.put("min_value", minValue);
    if (maxValue != Double.MAX_VALUE)
        json.put("max_value", maxValue);
    if (nominalWidth != 0)
        json.put("nominal_width", nominalWidth);
    if (compute != null)
        json.put("compute", compute);
    return json;/*from  ww w .j a v a  2s.c o m*/
}

From source file:com.googlecode.android_scripting.facade.ui.TimePickerDialogTask.java

@Override
public void onCreate() {
    super.onCreate();
    mDialog = new TimePickerDialog(getActivity(), new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hour, int minute) {
            JSONObject result = new JSONObject();
            try {
                result.put("which", "positive");
                result.put("hour", hour);
                result.put("minute", minute);
                setResult(result);/*ww  w .ja  va 2  s.  c  o  m*/
            } catch (JSONException e) {
                throw new AndroidRuntimeException(e);
            }
        }
    }, mHour, mMinute, mIs24Hour);
    mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface view) {
            JSONObject result = new JSONObject();
            try {
                result.put("which", "neutral");
                result.put("hour", mHour);
                result.put("minute", mMinute);
                setResult(result);
            } catch (JSONException e) {
                throw new AndroidRuntimeException(e);
            }
        }
    });
    mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        public void onDismiss(DialogInterface dialog) {
            JSONObject result = new JSONObject();
            try {
                result.put("which", "negative");
                result.put("hour", mHour);
                result.put("minute", mMinute);
                setResult(result);
            } catch (JSONException e) {
                throw new AndroidRuntimeException(e);
            }
        }
    });
    mDialog.show();
    mShowLatch.countDown();
}

From source file:ca.viaware.dlna.webinterface.InterfaceServer.java

public void start() {

    server.createContext("/list/", new HttpHandler() {

        private void exploreEntries(JSONArray children, ArrayList<LibraryEntry> entries, int parent) {
            for (LibraryEntry e : entries) {
                if (e.getParent() == parent) {
                    JSONObject entryJson = new JSONObject();
                    entryJson.put("name", e.getName());
                    entryJson.put("id", e.getId());
                    entryJson.put("type", e.getTypeID());
                    if (e.getTypeID() == EntryType.CONTAINER) {
                        JSONArray sub = new JSONArray();
                        entryJson.put("children", sub);
                        exploreEntries(sub, entries, e.getId());
                    }/*w  w w  .j  av a2s . c o  m*/
                    children.put(entryJson);
                }
            }
        }

        @Override
        public void handle(HttpExchange exchange) throws IOException {
            String json = (String) Library.runInstance(new LibraryInstanceRunner() {
                @Override
                public Object run(LibraryFactory factory) {
                    JSONArray root = new JSONArray();
                    ArrayList<LibraryEntry> entries = factory.getAll();

                    exploreEntries(root, entries, -1);
                    return new JSONObject().put("entries", root).toString(4);
                }
            });

            while (exchange.getRequestBody().read() != -1) {
            }

            byte[] bytes = json.getBytes("UTF-8");

            Headers headers = exchange.getResponseHeaders();
            headers.set("CONTENT-TYPE", "application/json");
            headers.set("CONTENT-LANGUAGE", "en");
            exchange.sendResponseHeaders(200, bytes.length);

            exchange.getResponseBody().write(bytes);
            exchange.getResponseBody().close();
        }
    });

    server.start();
    Log.info("Started Web Interface HTTP server");
}

From source file:com.shampan.services.PageService.java

public static String getCategorySubCategory() {
    JSONObject json = new JSONObject();
    json.put("categoryList", pageObject.getCategories());
    json.put("subCategoryList", pageObject.getSubCategories());
    return json.toString();
}

From source file:com.shampan.services.PageService.java

public static String getTimelinePhotos(String pageId, String userId) {
    JSONObject json = new JSONObject();
    json.put("pageInfo", pageObject.getPageInfo(pageId));
    json.put("pageMemberInfo", pageObject.getMemeberInfo(pageId, userId));
    json.put("photoList", pageObject.getTimelinePhotos(pageId));
    return json.toString();
}

From source file:com.shampan.services.PageService.java

public static String getAlbums(String pageId) {
    JSONObject albums = new JSONObject();
    albums.put("albumList", pageObject.getAlbums(pageId));
    return albums.toString();
}

From source file:com.shampan.services.PageService.java

public static String getPhotos(String userId, String mappingId, String albumId) {
    JSONObject photos = new JSONObject();
    photos.put("albumInfo", pageObject.getAlbum(userId, mappingId, albumId));
    photos.put("photoList", pageObject.getPhotos(mappingId, albumId));
    return photos.toString();
}

From source file:com.shampan.services.PageService.java

public static String getPageInfo(String pageId, String userId) {
    JSONObject json = new JSONObject();
    json.put("pageInfo", pageObject.getPageInfo(pageId));
    json.put("pageMemberInfo", pageObject.getMemeberInfo(pageId, userId));
    return json.toString();
}