当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray类代码示例

本文整理汇总了Java中com.amazonaws.util.json.JSONArray的典型用法代码示例。如果您正苦于以下问题:Java JSONArray类的具体用法?Java JSONArray怎么用?Java JSONArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JSONArray类属于com.amazonaws.util.json包,在下文中一共展示了JSONArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getListField

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
public List<String> getListField(String field) throws JSONException {
	List<String> rlt = null;
	
	if(fields.containsKey(field)) {
		String value = fields.get(field);
		JSONArray array = new JSONArray(value);
		if(array.length() > 0) {
			rlt = new ArrayList<String>();
			for(int i = 0; i < array.length(); i++) {
				rlt.add(array.getString(i));
			}
		}
	}
	
	return rlt;
}
 
开发者ID:tahseen,项目名称:amazon-cloudsearch-client-java,代码行数:17,代码来源:Hit.java

示例2: toJSON

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
private JSONObject toJSON(AmazonCloudSearchAddRequest document) throws JSONException {
	JSONObject doc = new JSONObject();
	doc.put("type", "add");
	doc.put("id", document.id.toLowerCase());
	doc.put("version", document.version);
	doc.put("lang", document.lang);
	
	JSONObject fields = new JSONObject();
	for(Map.Entry<String, Object> entry : document.fields.entrySet()) {
		if(entry.getValue() instanceof Collection) {
			JSONArray array = new JSONArray();
			Iterator i = ((Collection)entry.getValue()).iterator();
			while(i.hasNext()) {
				array.put(i.next());
			}
			fields.put(entry.getKey(), array);
		} else {
			fields.put(entry.getKey(), entry.getValue());
		}
	}
	doc.put("fields", fields);
	return doc;
}
 
开发者ID:tahseen,项目名称:amazon-cloudsearch-client-java,代码行数:24,代码来源:AmazonCloudSearchClient.java

示例3: decodeParams

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
private JSONObject decodeParams(String params) {
    Map<String, String[]> eparams =  Utils.decodeQueryString(params);
    JSONObject paramsObj = new JSONObject();
    for (String key : eparams.keySet()) {
        String[] vals = eparams.get(key);
        if (vals.length == 1) {
            try {
                paramsObj.put(key, Long.parseLong(vals[0]));   
            } catch (NumberFormatException e) {
                try {
                    paramsObj.put(key, Double.parseDouble(vals[0]));
                } catch (NumberFormatException e2) {
                    paramsObj.put(key, vals[0]);
                }
            }
        } else{
            JSONArray arr = new JSONArray();
            for (String s : vals) arr.put(s);
            paramsObj.put(key, arr);
        }
    }
    return paramsObj;
}
 
开发者ID:dataiku,项目名称:wt1,代码行数:24,代码来源:KafkaStorageProcessor.java

示例4: jsonObjectToListString

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
private List<String> jsonObjectToListString (JSONArray json) {
    if (json == null) {
      return null;
    }

    final List<String> list = new ArrayList<>();

    for (int i = 0; i < json.length(); i++) {
        try {
            list.add(json.getString(i));
        } catch (JSONException e) {}
    }

    return list;
}
 
开发者ID:awslabs,项目名称:aws-apigateway-importer,代码行数:16,代码来源:ApiGatewaySdkRamlApiImporter.java

示例5: isJSONValid

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
public static boolean isJSONValid(String test) {
	try {
		new JSONObject(test);
	} catch (JSONException ex) {
		try {
			new JSONArray(test);
		} catch (JSONException ex1) {
			return false;
		}
	}
	return true;
}
 
开发者ID:CityOfNewYork,项目名称:CROL-WebApp,代码行数:13,代码来源:CrolService.java

示例6: runAllParagraph

import com.amazonaws.util.json.JSONArray; //导入依赖的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;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:36,代码来源:ZeppelinhubClient.java

示例7: notifyComplete

import com.amazonaws.util.json.JSONArray; //导入依赖的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 );
    }
}
 
开发者ID:stevenmhood,项目名称:transcoder,代码行数:15,代码来源:TranscodeNotificationListener.java

示例8: createUserFromHNAPIResult

import com.amazonaws.util.json.JSONArray; //导入依赖的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;
	}
}
 
开发者ID:fivedogit,项目名称:hn_firebase_listener,代码行数:40,代码来源:FirebaseListener.java

示例9: validJSONArray

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
/**
 * Validates a JSON string representing JSON array.
 * @param text Text to validate
 * @return True, if text is a valid JSON array.
 */
private boolean validJSONArray(final String text) {
    boolean result = true;
    try {
        new JSONArray(text);
    } catch (final JSONException ex) {
        result = false;
    }
    return result;
}
 
开发者ID:jcabi,项目名称:jcabi-beanstalk-maven-plugin,代码行数:15,代码来源:AbstractBeanstalkMojo.java

示例10: fromJSON

import com.amazonaws.util.json.JSONArray; //导入依赖的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;
}
 
开发者ID:tahseen,项目名称:amazon-cloudsearch-client-java,代码行数:41,代码来源:AmazonCloudSearchClient.java

示例11: createItemFromHNAPIResult

import com.amazonaws.util.json.JSONArray; //导入依赖的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;
}
}
 
开发者ID:fivedogit,项目名称:hn_firebase_listener,代码行数:70,代码来源:FirebaseListener.java

示例12: addDocuments

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
/**
 * An add operation specifies either new documents that you want to add to the index or existing documents that you want to update.
 * An add operation is only applied to an existing document if the version number specified in the operation is greater than the existing document's version number.
 * 
 * @param documents The documents that need to added or updated
 * @throws JSONException 
 * @throws AwsCSMalformedRequestException 
 * @throws AwsCSInternalServerException 
 */
public void addDocuments(List<AmazonCloudSearchAddRequest> documents) throws JSONException, AmazonCloudSearchRequestException, AmazonCloudSearchInternalServerException {
	JSONArray docs = new JSONArray();
	for(AmazonCloudSearchAddRequest doc : documents) {
		docs.put(toJSON(doc));
	}
	updateDocumentRequest(docs.toString());
}
 
开发者ID:tahseen,项目名称:amazon-cloudsearch-client-java,代码行数:17,代码来源:AmazonCloudSearchClient.java

示例13: deleteDocuments

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
/**
 * A delete operation specifies existing documents that you want to delete.
 * A delete operation is only applied to an existing document if the version number specified in the operation is greater than the existing document's version number.
 * 
 * @param document
 * @throws AwsCSMalformedRequestException
 * @throws AwsCSInternalServerException
 * @throws JSONException
 */
public void deleteDocuments(List<AmazonCloudSearchDeleteRequest> documents) throws JSONException, AmazonCloudSearchRequestException, AmazonCloudSearchInternalServerException {
	JSONArray docs = new JSONArray();
	for(AmazonCloudSearchDeleteRequest doc : documents) {
		docs.put(toJSON(doc));
	}
	updateDocumentRequest(docs.toString());
}
 
开发者ID:tahseen,项目名称:amazon-cloudsearch-client-java,代码行数:17,代码来源:AmazonCloudSearchClient.java

示例14: addDocument

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
/**
 * An add operation specifies either a new document that you want to add to the index or an existing document that you want to update.
 * An add operation is only applied to an existing document if the version number specified in the operation is greater than the existing document's version number.
 * 
 * @param document The document that need to added or updated
 * @throws AwsCSMalformedRequestException 
 * @throws AwsCSInternalServerException 
 * @throws JSONException 
 */
public void addDocument(AmazonCloudSearchAddRequest document) throws AmazonCloudSearchRequestException, AmazonCloudSearchInternalServerException, JSONException {
	JSONArray docs = new JSONArray();
	docs.put(toJSON(document));
	updateDocumentRequest(docs.toString());
}
 
开发者ID:tahseen,项目名称:amazon-cloudsearch-client-java,代码行数:15,代码来源:AmazonCloudSearchClient.java

示例15: deleteDocument

import com.amazonaws.util.json.JSONArray; //导入依赖的package包/类
/**
 * A delete operation specifies an existing document that you want to delete.
 * A delete operation is only applied to an existing document if the version number specified in the operation is greater than the existing document's version number.
 * 
 * @param document
 * @throws AwsCSMalformedRequestException
 * @throws AwsCSInternalServerException
 * @throws JSONException
 */
public void deleteDocument(AmazonCloudSearchDeleteRequest document) throws AmazonCloudSearchRequestException, AmazonCloudSearchInternalServerException, JSONException {
	JSONArray docs = new JSONArray();
	docs.put(toJSON(document));
	updateDocumentRequest(docs.toString());
}
 
开发者ID:tahseen,项目名称:amazon-cloudsearch-client-java,代码行数:15,代码来源:AmazonCloudSearchClient.java


注:本文中的com.amazonaws.util.json.JSONArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。