本文整理汇总了Java中com.amazonaws.util.json.JSONObject.has方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.has方法的具体用法?Java JSONObject.has怎么用?Java JSONObject.has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.util.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.has方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateConfig
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
private Boolean validateConfig(JSONObject config)
{
Boolean valid = true;
if (!config.has("accessKeyId"))
{
System.out.println("config parameter 'accessKeyId' is missing.");
valid = false;
}
if (!config.has("secretAccessKey"))
{
System.out.println("config parameter 'secretAccessKey' is missing.");
valid = false;
}
if (!config.has("region"))
{
System.out.println("config parameter 'region' is missing.");
valid = false;
}
if (!config.has("tableName"))
{
System.out.println("config parameter 'tableName' is missing.");
valid = false;
}
return valid;
}
示例2: checkIfAttributesAreEqual
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
/**
* Check if all the keys and the values in the request are present in the response. The response might contain additional data which is ignored.
*
* @param requestAttributes
* @param responseAttributes
* @return
* @throws Exception
*/
public static boolean checkIfAttributesAreEqual(String requestAttributes, String responseAttributes) throws Exception {
JSONObject requestJson = new JSONObject(requestAttributes);
JSONObject responseJson = new JSONObject(responseAttributes);
Iterator iterator = requestJson.keys();
while (iterator.hasNext()) {
String requestAttribute = iterator.next().toString();
if (!responseJson.has(requestAttribute) || !requestJson.get(requestAttribute).equals(responseJson.get(requestAttribute)))
return false;
}
return true;
}
示例3: createUserFromHNAPIResult
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
private HNUserItem createUserFromHNAPIResult(String result)
{
if(result == null || result.isEmpty())
return null;
try
{
HNUserItem useritem = new HNUserItem();
JSONObject profile_jo = new JSONObject(result);
useritem.setId(profile_jo.getString("id"));
useritem.setCreated(profile_jo.getLong("created"));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("America/Louisville"));
useritem.setCreatedHumanReadable(sdf.format(profile_jo.getInt("karma")*1000));
useritem.setKarma(profile_jo.getInt("karma"));
if(profile_jo.has("about"))
useritem.setAbout(profile_jo.getString("about"));
useritem.setDelay(profile_jo.getInt("delay"));
if(profile_jo.has("submitted"))
{
JSONArray ja = profile_jo.getJSONArray("submitted");
HashSet<String> hs = new HashSet<String>();
if (ja != null)
{
int len = ja.length();
for (int i=0;i<len;i++)
{
hs.add(ja.get(i).toString());
}
useritem.setSubmitted(hs);
}
}
return useritem;
}
catch (JSONException e)
{
e.printStackTrace();
return null;
}
}
示例4: handle
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
public AmazonServiceException handle(HttpResponse response)
throws Exception {
JSONObject jsonBody = getBodyAsJson(response);
Class<? extends AmazonServiceException> exceptionClass = exceptionClasses.get(response.getStatusCode());
AmazonServiceException result;
// Support other attribute names for the message?
// TODO: Inspect exception type (caching details) and apply other values from the body
String message = jsonBody.has("message") ? jsonBody.getString("message") : jsonBody.getString("Message");
if (exceptionClass != null) {
result = exceptionClass.getConstructor(String.class).newInstance(message);
} else {
result = AmazonServiceException.class.getConstructor(String.class).newInstance(message);
}
result.setServiceName(response.getRequest().getServiceName());
result.setStatusCode(response.getStatusCode());
if (response.getStatusCode() < 500) {
result.setErrorType(ErrorType.Client);
} else {
result.setErrorType(ErrorType.Service);
}
for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) {
if (headerEntry.getKey().equalsIgnoreCase("X-Amzn-RequestId")) {
result.setRequestId(headerEntry.getValue());
}
}
return result;
}
示例5: checkIfAttributesContainKeyAndValue
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
public static boolean checkIfAttributesContainKeyAndValue(String attributes, String key, String value) throws Exception {
JSONObject jsonObject = new JSONObject(attributes);
if (!jsonObject.has(key) || !jsonObject.get(key).equals(value))
return false;
return true;
}
示例6: checkIfAttributesContainKey
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
public static boolean checkIfAttributesContainKey(String attributes, String key) throws Exception {
JSONObject jsonObject = new JSONObject(attributes);
if (!jsonObject.has(key))
return false;
return true;
}
示例7: createItemFromHNAPIResult
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
private HNItemItem createItemFromHNAPIResult(String unchecked_result)
{
if(unchecked_result == null || unchecked_result.isEmpty())
{
System.err.println("Error trying to create new item in DB: result string from HN api was null or empty");
return null;
}
try{
HNItemItem hnii = null;
JSONObject new_jo = new JSONObject(unchecked_result);
// these are the required fields (as far as we're concerned)
// without them, we can't even make sense of what to do with it
if(new_jo.has("id") && new_jo.has("by") && new_jo.has("time") && new_jo.has("type"))
{
//** THESE FIELDS MUST MATCH HNItemItem EXACTLY ***
hnii = new HNItemItem();
hnii.setId(new_jo.getLong("id"));
hnii.setBy(new_jo.getString("by"));
hnii.setTime(new_jo.getLong("time"));
hnii.setType(new_jo.getString("type"));
if(new_jo.has("dead") && new_jo.getBoolean("dead") == true)
hnii.setDead(true);
else
hnii.setDead(false);
if(new_jo.has("deleted") && new_jo.getBoolean("deleted") == true)
hnii.setDeleted(true);
else
hnii.setDeleted(false);
if(new_jo.has("parent"))
hnii.setParent(new_jo.getLong("parent"));
if(new_jo.has("score"))
hnii.setScore(new_jo.getLong("score"));
if(new_jo.has("kids"))
{
HashSet<Long> kids_ts = new HashSet<Long>();
JSONArray ja = new_jo.getJSONArray("kids");
if(ja != null && ja.length() > 0)
{
int x = 0;
while(x < ja.length())
{
kids_ts.add(ja.getLong(x));
x++;
}
if(kids_ts.size() == ja.length()) // if the number of items has changed for some reason, just skip bc something has messed up
{
System.out.println("createHNItemFromHNAPIResult setting kids=" + kids_ts.size());
hnii.setKids(kids_ts);
}
}
else
hnii.setKids(null);
}
if(new_jo.has("url"))
hnii.setURL(new_jo.getString("url"));
return hnii;
}
else
{
System.err.println("Error trying to create new item in DB: missing required id, by, time or type values");
return null;
}
}
catch(JSONException jsone)
{
System.err.println("Error trying to create new item in DB: result string was not valid JSON.");
return null;
}
}