use of org.json.JSONException in project weiciyuan by qii.
the class FriendsTimeLineTagDao method getGSONMsgList.
public List<TagBean> getGSONMsgList() throws WeiboException {
String json = getMsgListJson();
List<TagBean> tagBeanList = new ArrayList<TagBean>();
try {
JSONArray array = new JSONArray(json);
int size = array.length();
for (int i = 0; i < size; i++) {
TagBean bean = new TagBean();
JSONObject jsonObject = array.getJSONObject(i);
Iterator<String> iterator = jsonObject.keys();
while (iterator.hasNext()) {
String key = iterator.next();
if (key.equalsIgnoreCase("weight")) {
String value = jsonObject.optString(key);
bean.setWeight(value);
} else {
String value = jsonObject.optString(key);
bean.setId(Integer.valueOf(key));
bean.setName(value);
}
}
tagBeanList.add(bean);
}
} catch (JSONException e) {
AppLogger.e(e.getMessage());
}
return tagBeanList;
}
use of org.json.JSONException in project platformlayer by platformlayer.
the class ServiceAuthorizationResource method createService.
// We deliberately don't support this at the moment... it's quite restrictive on our data store
// @GET
// @Produces({ APPLICATION_XML, APPLICATION_JSON })
// public <T> ServiceAuthorizationCollection getAll() {
// List<ServiceAuthorization> items = authorizationRepository.getByAccountId(getAccountId());
// ServiceAuthorizationCollection collection = new ServiceAuthorizationCollection();
// collection.items = items;
// return collection;
// }
@POST
@Consumes({ XML, JSON })
@Produces({ XML, JSON })
public <T> ServiceAuthorization createService(final ServiceAuthorization authorization) throws OpsException, RepositoryException {
ServiceType serviceType = getServiceType();
authorization.serviceType = serviceType.getKey();
final ServiceProvider serviceProvider = opsSystem.getServiceProvider(serviceType);
if (serviceProvider == null) {
log.warn("Unknown serviceProvider: " + serviceType);
throw new WebApplicationException(404);
}
String data = authorization.data;
if (Strings.isNullOrEmpty(data)) {
throw new IllegalArgumentException("Data is required");
}
data = data.trim();
if (data.startsWith("{")) {
// Convert to XML
SettingCollection settings = new SettingCollection();
settings.items = Lists.newArrayList();
// We presume it's a simple map of keys and values
try {
JSONObject json = new JSONObject(data);
@SuppressWarnings("unchecked") Iterator<String> keys = json.keys();
while (keys.hasNext()) {
String key = keys.next();
String value = json.getString(key);
Setting setting = new Setting();
setting.key = key;
setting.value = value;
settings.items.add(setting);
}
} catch (JSONException e) {
throw new IllegalArgumentException("Error parsing data", e);
}
JaxbHelper jaxbHelper = JaxbHelper.get(SettingCollection.class);
String xml;
try {
xml = jaxbHelper.marshal(settings, false);
} catch (JAXBException e) {
throw new IllegalArgumentException("Error converting JSON to XML", e);
}
authorization.data = xml;
}
// Authentication authentication = getAuthentication();
//
// OpsContextBuilder opsContextBuilder = opsSystem.getInjector().getInstance(OpsContextBuilder.class);
// final OpsContext opsContext = opsContextBuilder.buildOpsContext(serviceType, authentication, false);
//
// OpsContext.runInContext(opsContext, new CheckedCallable<Object, Exception>() {
// @Override
// public Object call() throws Exception {
// serviceProvider.validateAuthorization(authorization);
// return null;
// }
// });
// serviceProvider.validateAuthorization(authorization);
ServiceAuthorization created = authorizationRepository.createAuthorization(getProject(), authorization);
// For security, never return the data
created.data = null;
return created;
}
use of org.json.JSONException in project platformlayer by platformlayer.
the class ActionsResource method doActionJson.
@POST
@Consumes({ JSON })
@Produces({ XML, JSON })
public JobData doActionJson(String json) throws IOException, RepositoryException, OpsException {
JSONObject jsonObject;
String actionType = null;
try {
jsonObject = new JSONObject(json);
Object typeObject = jsonObject.remove("type");
if (typeObject != null) {
actionType = typeObject.toString();
}
// Remove type attribute
json = jsonObject.toString();
} catch (JSONException e) {
throw new IllegalArgumentException("Malformed JSON", e);
}
if (Strings.isNullOrEmpty(actionType)) {
throw new IllegalArgumentException("Must pass type attribute");
}
Map<String, Class<? extends Action>> actionMap = Maps.newHashMap();
actionMap.put("configureaction", ConfigureAction.class);
actionMap.put("validateaction", ValidateAction.class);
// actionMap.put("deleteaction", DeleteAction.class);
actionMap.put("backupaction", BackupAction.class);
for (Class<? extends Action> action : getServiceProvider().getActions()) {
String key = action.getSimpleName().toLowerCase();
actionMap.put(key, action);
}
Class<? extends Action> actionClass = actionMap.get(actionType.toLowerCase());
if (actionClass == null) {
throw new IllegalArgumentException("Unknown action: " + actionType);
}
Action action = jsonMapper.readItem(actionClass, json);
return doAction(action);
}
use of org.json.JSONException in project platform_frameworks_base by android.
the class AutomaticActivity method beginTest.
private void beginTest() {
mFinalCallbacks.add(new FinalCallback() {
@Override
void report(String name, float value) {
Log.d(LOG_TAG, name + " " + value);
}
;
});
File inputFile = new File(Environment.getExternalStorageDirectory(), "CanvasCompareInput.json");
if (inputFile.exists() && inputFile.canRead() && inputFile.length() > 0) {
try {
FileInputStream inputStream = new FileInputStream(inputFile);
Log.d(LOG_TAG, "Parsing input file...");
StringBuffer content = new StringBuffer((int) inputFile.length());
byte[] buffer = new byte[1024];
while (inputStream.read(buffer) != -1) {
content.append(new String(buffer));
}
mInputJson = new JSONObject(content.toString());
inputStream.close();
Log.d(LOG_TAG, "Parsed input file with " + mInputJson.length() + " entries");
} catch (JSONException e) {
Log.e(LOG_TAG, "error parsing input json", e);
} catch (IOException e) {
Log.e(LOG_TAG, "error reading input json from sd", e);
}
}
mOutputJson = new JSONObject();
}
use of org.json.JSONException in project androidquery by androidquery.
the class AjaxLoadingActivity method cookieCb.
public void cookieCb(String url, JSONObject jo, AjaxStatus status) {
JSONObject result = new JSONObject();
try {
result.putOpt("cookies", jo.optJSONObject("cookies"));
} catch (JSONException e) {
}
showResult(result, status);
}
Aggregations