本文整理汇总了Java中com.amazonaws.util.json.JSONObject.getJSONArray方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.getJSONArray方法的具体用法?Java JSONObject.getJSONArray怎么用?Java JSONObject.getJSONArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.util.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.getJSONArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runAllParagraph
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
boolean runAllParagraph(String noteId, String hubMsg) {
LOG.info("Running paragraph with noteId {}", noteId);
try {
JSONObject data = new JSONObject(hubMsg);
if (data.equals(JSONObject.NULL) || !(data.get("data") instanceof JSONArray)) {
LOG.error("Wrong \"data\" format for RUN_NOTEBOOK");
return false;
}
Client client = Client.getInstance();
if (client == null) {
LOG.warn("Base client isn't initialized, returning");
return false;
}
Message zeppelinMsg = new Message(OP.RUN_PARAGRAPH);
JSONArray paragraphs = data.getJSONArray("data");
String principal = data.getJSONObject("meta").getString("owner");
for (int i = 0; i < paragraphs.length(); i++) {
if (!(paragraphs.get(i) instanceof JSONObject)) {
LOG.warn("Wrong \"paragraph\" format for RUN_NOTEBOOK");
continue;
}
zeppelinMsg.data = gson.fromJson(paragraphs.getString(i),
new TypeToken<Map<String, Object>>(){}.getType());
zeppelinMsg.principal = principal;
zeppelinMsg.ticket = TicketContainer.instance.getTicket(principal);
client.relayToZeppelin(zeppelinMsg, noteId);
LOG.info("\nSending RUN_PARAGRAPH message to Zeppelin ");
}
} catch (JSONException e) {
LOG.error("Failed to parse RUN_NOTEBOOK message from ZeppelinHub ", e);
return false;
}
return true;
}
示例2: notifyComplete
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
private void notifyComplete( final JSONObject jsonMessage ) throws JSONException
{
final String jobId = jsonMessage.getString( "jobId" );
final String inputKey = jsonMessage.getJSONObject( "input" ).getString( "key" );
final JSONArray jsonOutputList = jsonMessage.getJSONArray( "outputs" );
for ( int i = 0; i < jsonOutputList.length(); i++ )
{
final JSONObject jsonOutput = jsonOutputList.getJSONObject( i );
final String outputKey = jsonOutput.getString( "key" );
final TranscodeEvent completedTranscodeEvent =
new TranscodeEvent( jobId, new MovieId( inputKey ), new MovieId( outputKey ) );
this.transcodeEventHandler.onTranscodeComplete( completedTranscodeEvent );
}
}
示例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: fromJSON
import com.amazonaws.util.json.JSONObject; //导入方法依赖的package包/类
private AmazonCloudSearchResult fromJSON(String responseBody) throws JSONException {
AmazonCloudSearchResult result = new AmazonCloudSearchResult();
JSONObject root = new JSONObject(responseBody);
JSONObject status = root.getJSONObject("status");
if(status != null) {
result.rid = status.getString("rid");
result.time = status.getLong("time-ms");
}
JSONObject hits = root.getJSONObject("hits");
if(hits != null) {
result.found = hits.getInt("found");
result.start = hits.getInt("start");
if(result.found > 0) {
JSONArray hitArray = hits.getJSONArray("hit");
if(hitArray != null) {
for(int i = 0; i < hitArray.length(); i++) {
JSONObject row = hitArray.getJSONObject(i);
Hit hit = new Hit();
hit.id = row.getString("id");
JSONObject fields = row.getJSONObject("fields");
String[] names = JSONObject.getNames(fields);
for(String name : names) {
if(hit.fields == null) {
hit.fields = new HashMap<String, String>();
}
hit.fields.put(name, fields.getString(name));
}
if(result.hits == null) {
result.hits = new ArrayList<Hit>();
}
result.hits.add(hit);
}
}
}
}
return result;
}
示例5: 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;
}
}