public static List<Message> decodePayload(final String jsonString) { if (jsonString == null || jsonString.trim().length() == 0) return Collections.emptyList(); final JSONValue val = JSONParser.parseStrict(jsonString); if (val == null || val.isArray() == null) { throw new RuntimeException("illegal payload: must be JSONArray"); } final JSONArray jsonArray = val.isArray(); final List<Message> messageList = new ArrayList<Message>(jsonArray.size()); for (int i = 0; i < jsonArray.size(); i++) { messageList.add(decodeCommandMessage(GWTJSON.wrap(jsonArray.get(i)))); } return messageList; }
if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); if ((jsonArray = jsonValue.isArray()) == null) { Window.alert("Error parsing the JSON"); if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); Window.alert(jsonString.stringValue()); // Finally!
protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException { super(ShapeType.MULTI_PATH, node, ctx); final JSONValue pval = node.get("path-list"); if (null != pval) { final JSONArray list = pval.isArray(); if (null != list) { final int size = list.size(); for (int i = 0; i < size; i++) { final JSONValue lval = list.get(i); if (null != lval) { final JSONArray path = lval.isArray(); if (null != path) { final PathPartListJSO pjso = path.getJavaScriptObject().cast(); add(new PathPartList(pjso, true)); } } } } } }
private Object fromJsonValue(JSONValue elem) { if (elem.isString() != null) { return elem.isString().stringValue(); } else if (elem.isNumber() != null) { return elem.isNumber().doubleValue(); } else if (elem.isArray() != null) { return asList(elem.isArray()); } else if (elem.isNull() != null) { return null; } else if (elem.isObject() != null) { return asMap(elem.isObject()); } else { return ""; } } }
/** * Get a child JSON array from a parent JSON object. * * @param jsonObject The parent JSON object. * @param key The name of the child object. * @return Returns the child JSON array if it could be found, or null if the value was null. * @throws JSONException In case something went wrong while searching for the child. */ public static JSONArray getChildArray(JSONObject jsonObject, String key) throws JSONException { checkArguments(jsonObject, key); JSONValue value = jsonObject.get(key); if (value != null) { if (value.isArray() != null) { return value.isArray(); } else if (value.isNull() != null) { return null; } throw new JSONException("Child is not a JSONArray, but a: " + value.getClass()); } return null; }
protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException { super(ShapeType.MULTI_PATH, node, ctx); JSONValue pval = node.get("path-list"); if (null != pval) { final JSONArray list = pval.isArray(); if (null != list) { final int size = list.size(); for (int i = 0; i < size; i++) { final JSONValue lval = list.get(i); if (null != lval) { final JSONArray path = lval.isArray(); if (null != path) { PathPartListJSO pjso = path.getJavaScriptObject().cast(); add(new PathPartList(pjso, true)); } } } } } }
@Override public List<T> readList(String jsonString, String arrayKey) { List<T> models = null; if (jsonString != null && jsonString.trim().length() != 0) { JSONObject jsonObject = JSONParser.parseStrict(jsonString).isObject(); if (jsonObject != null) { if (arrayKey != null) { JSONValue jsonValue = jsonObject.get(arrayKey); if (jsonValue != null) { JSONArray jsonArray = jsonValue.isArray(); if (jsonArray != null) { models = readList(jsonArray); } } } } else { throw new JSONException("\"" + jsonString + "\" represents invalid json data!"); } } return models; }
public static List<Message> decodePayload(final String jsonString) { if (jsonString == null || jsonString.trim().length() == 0) return Collections.emptyList(); final JSONValue val = JSONParser.parseStrict(jsonString); if (val == null || val.isArray() == null) { throw new RuntimeException("illegal payload: must be JSONArray"); } final JSONArray jsonArray = val.isArray(); final List<Message> messageList = new ArrayList<Message>(jsonArray.size()); for (int i = 0; i < jsonArray.size(); i++) { messageList.add(decodeCommandMessage(GWTJSON.wrap(jsonArray.get(i)))); } return messageList; }
if (string != null){return new JSONString(string.stringValue());} JSONNull aNull = jsonValue.isNull(); if (aNull != null){return JSONNull.getInstance();} if (number!=null){return new JSONNumber(number.doubleValue());} JSONObject jsonObject = jsonValue.isObject(); if (jsonObject!=null){ JSONObject clonedObject = new JSONObject(); JSONArray array = jsonValue.isArray(); if (array != null){ JSONArray clonedArray = new JSONArray();
if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); if ((jsonArray = jsonValue.isArray()) == null) { Window.alert("Error parsing the JSON"); jsonValue = jsonArray.get(i); if ((jsonObject = jsonValue.isObject()) == null) { Window.alert("Error parsing the JSON"); Window.alert("Error parsing the JSON"); guestAgent.setArchitecture(jsonString.stringValue()); Window.alert("Error parsing the JSON"); guestAgent.setHypervisor(jsonString.stringValue()); Window.alert("Error parsing the JSON"); guestAgent.setMd5hash(jsonString.stringValue());
public List<FBScript> decodeScripts(JSONValue json) throws FormEncodingException { List<FBScript> retval = new ArrayList<FBScript>(); if (json != null && json.isArray() != null) { JSONArray array = json.isArray(); for (int index = 0; index < array.size(); index++) { JSONValue elem = array.get(index); JSONObject jsonObj = elem.isObject(); retval.add((FBScript) decode(asMap(jsonObj))); } } return retval; }
protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException { super(ShapeType.MULTI_PATH, node, ctx); final JSONValue pval = node.get("path-list"); if (null != pval) { final JSONArray list = pval.isArray(); if (null != list) { final int size = list.size(); for (int i = 0; i < size; i++) { final JSONValue lval = list.get(i); if (null != lval) { final JSONArray path = lval.isArray(); if (null != path) { final PathPartListJSO pjso = path.getJavaScriptObject().cast(); add(new PathPartList(pjso, true)); } } } } } }
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); LightArray<ContactAddress> addresses = getAddressArray(jsonContact.get(CONTACT_ADDRESSES).isArray()); contact.setContactAddresses(addresses); LightArray<ContactOrganisation> organisations = getContactOrganisationArray(jsonContact.get(CONTACT_ORGANISATION).isArray()); contact.setOrganisations(organisations);
@Override public void validate(final JSONValue jval, final ValidationContext ctx) throws ValidationException { if (null == jval) { ctx.addBadTypeError(getTypeName()); return; } final JSONArray jarr = jval.isArray(); if (null == jarr) { ctx.addBadTypeError(getTypeName()); } else { final int size = jarr.size(); for (int i = 0; i < size; i++) { ctx.pushIndex(i); m_elementTypeValidator.validate(jarr.get(i), ctx); ctx.pop();// index } } } }
public List<FBValidation> decodeValidations(JSONValue json) throws FormEncodingException { List<FBValidation> retval = new ArrayList<FBValidation>(); if (json != null && json.isArray() != null) { JSONArray array = json.isArray(); for (int index = 0; index < array.size(); index++) { JSONValue elem = array.get(index); JSONObject jsonObj = elem.isObject(); retval.add((FBValidation) decode(asMap(jsonObj))); } } return retval; }
protected MultiPath(final JSONObject node, final ValidationContext ctx) throws ValidationException { super(ShapeType.MULTI_PATH, node, ctx); final JSONValue pval = node.get("path-list"); if (null != pval) { final JSONArray list = pval.isArray(); if (null != list) { final int size = list.size(); for (int i = 0; i < size; i++) { final JSONValue lval = list.get(i); if (null != lval) { final JSONArray path = lval.isArray(); if (null != path) { final PathPartListJSO pjso = path.getJavaScriptObject().cast(); add(new PathPartList(pjso, true)); } } } } } }
@Override public void validate(final JSONValue jval, final ValidationContext ctx) throws ValidationException { if (null == jval) { ctx.addBadTypeError(getTypeName()); return; } final JSONArray jarr = jval.isArray(); if (null == jarr) { ctx.addBadTypeError(getTypeName()); } else { final int size = jarr.size(); for (int i = 0; i < size; i++) { ctx.pushIndex(i); m_elementTypeValidator.validate(jarr.get(i), ctx); ctx.pop();// index } } } }