Search in sources :

Example 1 with JSONArray

use of com.google.gwt.json.client.JSONArray in project gwtphonegap by dankurka.

the class ContactBrowserImpl method fromJSON.

public static Contact fromJSON(ContactsBrowserImpl controller, JSONObject jsonContact) {
    ContactBrowserImpl contact = new ContactBrowserImpl(controller);
    // simple fields
    contact.setId(getFieldAsString(jsonContact.get(FIELD_ID)));
    contact.setDisplayName(getFieldAsString(jsonContact.get(CONTACT_DISPLAY_NAME)));
    contact.setNickName(getFieldAsString(jsonContact.get(CONTACT_NICK_NAME)));
    contact.setNote(getFieldAsString(jsonContact.get(CONTACT_NOTE)));
    // birthday
    JSONValue dateValue = jsonContact.get(CONTACT_BIRTHDAY);
    if (dateValue != null && dateValue.isNumber() != null) {
        contact.setBirthDay(new Date((long) dateValue.isNumber().doubleValue()));
    }
    // contact fields
    JSONArray phoneNumberArray = jsonContact.get(CONTACT_PHONE_NUMBERS).isArray();
    LightArray<ContactField> phoneNumbers = getContactFieldsForArray(phoneNumberArray);
    contact.setPhoneNumbers(phoneNumbers);
    JSONArray emailsArray = jsonContact.get(CONTACT_EMAILS).isArray();
    LightArray<ContactField> emails = getContactFieldsForArray(emailsArray);
    contact.setEmails(emails);
    JSONArray imsArray = jsonContact.get(CONTACT_IMS).isArray();
    LightArray<ContactField> ims = getContactFieldsForArray(imsArray);
    contact.setIms(ims);
    JSONArray photosArray = jsonContact.get(CONTACT_PHOTOS).isArray();
    LightArray<ContactField> photos = getContactFieldsForArray(photosArray);
    contact.setPhotos(photos);
    JSONArray categoriesArray = jsonContact.get(CONTACT_CATEGORIES).isArray();
    LightArray<ContactField> categories = getContactFieldsForArray(categoriesArray);
    contact.setCategories(categories);
    JSONArray urlsArray = jsonContact.get(CONTACT_URLS).isArray();
    LightArray<ContactField> urls = getContactFieldsForArray(urlsArray);
    contact.setUrls(urls);
    ContactName name = getName(jsonContact.get(CONTACT_NAME).isObject());
    contact.setName(name);
    LightArray<ContactAddress> addresses = getAddressArray(jsonContact.get(CONTACT_ADDRESSES).isArray());
    contact.setContactAddresses(addresses);
    LightArray<ContactOrganisation> organisations = getContactOrganisationArray(jsonContact.get(CONTACT_ORGANISATION).isArray());
    contact.setOrganisations(organisations);
    return contact;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) ContactAddress(com.googlecode.gwtphonegap.client.contacts.ContactAddress) JSONArray(com.google.gwt.json.client.JSONArray) ContactField(com.googlecode.gwtphonegap.client.contacts.ContactField) ContactName(com.googlecode.gwtphonegap.client.contacts.ContactName) Date(java.util.Date) ContactOrganisation(com.googlecode.gwtphonegap.client.contacts.ContactOrganisation)

Example 2 with JSONArray

use of com.google.gwt.json.client.JSONArray in project gwtphonegap by dankurka.

the class ContactBrowserImpl method createOrganisation.

private JSONArray createOrganisation(LightArray<ContactOrganisation> organisations) {
    JSONArray jsonArray = new JSONArray();
    for (int i = 0; i < organisations.length(); i++) {
        ContactOrganisation co = organisations.get(i);
        JSONObject orga = new JSONObject();
        orga.put(ORGANISATION_NAME, getAsJSONString(co.getName()));
        orga.put(ORGANISATION_DEPARTMENT, getAsJSONString(co.getDepartment()));
        orga.put(ORGANISATION_TITLE, getAsJSONString(co.getTitle()));
        orga.put(ORGANISATION_TYPE, getAsJSONString(co.getType()));
        orga.put(ORGANISATION_PREF, JSONBoolean.getInstance(co.isPref()));
        jsonArray.set(i, orga);
    }
    return jsonArray;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) JSONArray(com.google.gwt.json.client.JSONArray) ContactOrganisation(com.googlecode.gwtphonegap.client.contacts.ContactOrganisation)

Example 3 with JSONArray

use of com.google.gwt.json.client.JSONArray in project che by eclipse.

the class JsonHelper method toMapOfLists.

public static Map<String, List<String>> toMapOfLists(String jsonStr) {
    Map<String, List<String>> map = new HashMap<>();
    JSONValue parsed = JSONParser.parseStrict(jsonStr);
    JSONObject jsonObj = parsed.isObject();
    if (jsonObj != null) {
        for (String key : jsonObj.keySet()) {
            JSONValue jsonValue = jsonObj.get(key);
            JSONArray jsonArray = jsonValue.isArray();
            List<String> values = new ArrayList<>();
            for (int i = 0; i < jsonArray.size(); i++) {
                values.add(jsonArray.get(i).isString().stringValue());
            }
            map.put(key, values);
        }
    }
    return map;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) HashMap(java.util.HashMap) JSONArray(com.google.gwt.json.client.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString)

Example 4 with JSONArray

use of com.google.gwt.json.client.JSONArray in project che by eclipse.

the class StringListUnmarshaller method toList.

public List<String> toList(String jsonStr) {
    JSONValue parsed = JSONParser.parseStrict(jsonStr);
    JSONArray jsonArray = parsed.isArray();
    if (jsonArray == null) {
        return Collections.emptyList();
    }
    List<String> list = new ArrayList<>();
    for (int i = 0; i < jsonArray.size(); i++) {
        JSONValue jsonValue = jsonArray.get(i);
        JSONString jsonString = jsonValue.isString();
        String stringValue = (jsonString == null) ? jsonValue.toString() : jsonString.stringValue();
        list.add(stringValue);
    }
    return list;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONArray(com.google.gwt.json.client.JSONArray) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString) JSONString(com.google.gwt.json.client.JSONString)

Example 5 with JSONArray

use of com.google.gwt.json.client.JSONArray in project opentsdb by OpenTSDB.

the class QueryUi method refreshLogs.

private void refreshLogs() {
    asyncGetJson(LOGS_URL, new GotJsonCallback() {

        public void got(final JSONValue json) {
            final JSONArray logmsgs = json.isArray();
            final int nmsgs = logmsgs.size();
            final FlexTable.FlexCellFormatter fcf = logs.getFlexCellFormatter();
            final FlexTable.RowFormatter rf = logs.getRowFormatter();
            for (int i = 0; i < nmsgs; i++) {
                final String msg = logmsgs.get(i).isString().stringValue();
                String part = msg.substring(0, msg.indexOf('\t'));
                logs.setText(i * 2, 0, new Date(Integer.valueOf(part) * 1000L).toString());
                // So we can change the style ahead.
                logs.setText(i * 2 + 1, 0, "");
                int pos = part.length() + 1;
                part = msg.substring(pos, msg.indexOf('\t', pos));
                if ("WARN".equals(part)) {
                    rf.getElement(i * 2).getStyle().setBackgroundColor("#FCC");
                    rf.getElement(i * 2 + 1).getStyle().setBackgroundColor("#FCC");
                } else if ("ERROR".equals(part)) {
                    rf.getElement(i * 2).getStyle().setBackgroundColor("#F99");
                    rf.getElement(i * 2 + 1).getStyle().setBackgroundColor("#F99");
                } else {
                    rf.getElement(i * 2).getStyle().clearBackgroundColor();
                    rf.getElement(i * 2 + 1).getStyle().clearBackgroundColor();
                    if ((i % 2) == 0) {
                        rf.addStyleName(i * 2, "subg");
                        rf.addStyleName(i * 2 + 1, "subg");
                    }
                }
                pos += part.length() + 1;
                // level
                logs.setText(i * 2, 1, part);
                part = msg.substring(pos, msg.indexOf('\t', pos));
                pos += part.length() + 1;
                // thread
                logs.setText(i * 2, 2, part);
                part = msg.substring(pos, msg.indexOf('\t', pos));
                pos += part.length() + 1;
                if (part.startsWith("net.opentsdb.")) {
                    part = part.substring(13);
                } else if (part.startsWith("org.hbase.")) {
                    part = part.substring(10);
                }
                // logger
                logs.setText(i * 2, 3, part);
                // message
                logs.setText(i * 2 + 1, 0, msg.substring(pos));
                fcf.setColSpan(i * 2 + 1, 0, 4);
                rf.addStyleName(i * 2, "fwf");
                rf.addStyleName(i * 2 + 1, "fwf");
            }
        }
    });
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONArray(com.google.gwt.json.client.JSONArray) JSONString(com.google.gwt.json.client.JSONString) Date(java.util.Date)

Aggregations

JSONArray (com.google.gwt.json.client.JSONArray)260 JSONString (com.google.gwt.json.client.JSONString)182 JSONNumber (com.google.gwt.json.client.JSONNumber)68 JSONObject (com.google.gwt.json.client.JSONObject)62 JSONValue (com.google.gwt.json.client.JSONValue)10 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)8 Point (org.rstudio.studio.client.workbench.views.plots.model.Point)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Date (java.util.Date)5 Map (java.util.Map)5 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 JsArrayString (com.google.gwt.core.client.JsArrayString)2 JSONBoolean (com.google.gwt.json.client.JSONBoolean)2 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)2 ContactOrganisation (com.googlecode.gwtphonegap.client.contacts.ContactOrganisation)2 Test (org.junit.Test)2 EntryPoint (com.google.gwt.core.client.EntryPoint)1 Style (com.google.gwt.dom.client.Style)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1