本文整理汇总了Java中com.ibm.json.java.JSONArray.get方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.get方法的具体用法?Java JSONArray.get怎么用?Java JSONArray.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.json.java.JSONArray
的用法示例。
在下文中一共展示了JSONArray.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPolygonsFromJson
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
private ArrayList<ArrayList<Point>> getPolygonsFromJson(JSONArray coordinates) {
ArrayList<ArrayList<Point>> polygons = new ArrayList<ArrayList<Point>>();
for (int i = 0; i < coordinates.size(); i++) {
JSONArray polygon = (JSONArray) coordinates.get(i);
ArrayList<Point> points = new ArrayList<Point>();
for (int j = 0; j < polygon.size(); j++) {
JSONArray point = (JSONArray)polygon.get(j);
points.add(new Point(objToInt(point.get(0)), objToInt(point.get(0))));
}
polygons.add(points);
}
return polygons;
}
示例2: WatsonUserModeller
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
public WatsonUserModeller()
{
try {
String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
JSONObject vcap;
vcap = (JSONObject) JSONObject.parse(VCAP_SERVICES);
watson = (JSONArray) vcap.get("personality_insights");
watsonInstance = (JSONObject) watson.get(0);
watsonCredentials = (JSONObject) watsonInstance.get("credentials");
} catch (IOException e) {
e.printStackTrace();
}
this.username = (String) watsonCredentials.get("username");
this.password = (String) watsonCredentials.get("password");
this.base_url = (String) watsonCredentials.get("url");
this.profile_api = Config.WATSON_PROF_API;
this.visual_api = Config.WATSON_VIZ_API;
this.executor = Executor.newInstance().auth(username, password);
if (this.executor == null)
{
System.err.println("Authentication failed in WatsonUserModeller.");
}
}
示例3: CloudantClient
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
public CloudantClient()
{
this.httpClient = null;
try {
String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
JSONObject vcap;
vcap = (JSONObject) JSONObject.parse(VCAP_SERVICES);
cloudant = (JSONArray) vcap.get("cloudantNoSQLDB");
cloudantInstance = (JSONObject) cloudant.get(0);
cloudantCredentials = (JSONObject) cloudantInstance.get("credentials");
} catch (IOException e) {
e.printStackTrace();
}
this.port = Config.CLOUDANT_PORT;
this.host = (String) cloudantCredentials.get("host");
this.username = (String) cloudantCredentials.get("username");
this.password = (String) cloudantCredentials.get("password");
this.name = Config.CLOUDANT_NAME;
this.dbc = this.createDBConnector();
}
示例4: calculateConfidence
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
private float calculateConfidence(JSONArray categoriesArray) throws Exception{
// Get categories in order of priority
float currentConfidence = 0;
try{
String[] configCategories = GDPRConfig.getCategories();
for( int i = 0; i < configCategories.length; i++ ){ // categories in order of weightage
String category = configCategories[i];
// calculate weightage for this category
for( int j = 0; j < categoriesArray.size(); j++ ){
JSONObject piiDataCategoryNode = (JSONObject)categoriesArray.get(j);
JSONArray attributesArray = (JSONArray)piiDataCategoryNode.get(category);
if( attributesArray != null ){
// calculate weightage for all PII entries in this node
for( int k = 0; k < attributesArray.size(); k++ ){
JSONObject piiNode = (JSONObject)attributesArray.get(k);
String piiType = piiNode.get("piitype").toString();
String pii = piiNode.get("pii").toString();
float weight = ((Float)piiNode.get("weight")).floatValue();
currentConfidence = getUpdatedConfidence(weight, currentConfidence);
}
}
}
}
return currentConfidence/100;
}catch( Exception e){
e.printStackTrace();
throw e;
}
}
示例5: getNLUCredentials
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
private Map<String, String> getNLUCredentials() throws Exception{
Map<String, String> nluCredentialsMap = new HashMap<String, String>();
try{
String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
//String VCAP_SERVICES = "{\"natural-language-understanding\":[{\"credentials\":{\"url\":\"https://gateway.watsonplatform.net/natural-language-understanding/api\",\"username\":\"8ea86c6c-c681-4186-bf91-e766413145ad\",\"password\":\"XaQHFNhhpnKX\"},\"syslog_drain_url\":null,\"volume_mounts\":[],\"label\":\"natural-language-understanding\",\"provider\":null,\"plan\":\"free\",\"name\":\"NLU - GDPR\",\"tags\":[\"watson\",\"ibm_created\",\"ibm_dedicated_public\",\"lite\"]}]}";
if (VCAP_SERVICES != null) {
// parse the VCAP JSON structure
JSONObject obj = (JSONObject) JSONObject.parse(VCAP_SERVICES);
JSONArray nluArray = (JSONArray)obj.get("natural-language-understanding");
if( nluArray != null && nluArray.size() > 0 ){
for( int i = 0; i < nluArray.size(); i++ ){
JSONObject o = (JSONObject)nluArray.get(i);
if( o.get("credentials") != null ){
JSONObject credsObject = (JSONObject)o.get("credentials");
nluCredentialsMap.put("username", (String)credsObject.get("username"));
nluCredentialsMap.put("password", (String)credsObject.get("password"));
nluCredentialsMap.put("nluURL", (String)credsObject.get("url"));
}
}
}
}
}catch(Exception e){
e.printStackTrace();
throw new Exception(e.getMessage());
}
if( nluCredentialsMap.get("username") == null ){
throw new Exception("NLU Credentials not found");
}
return nluCredentialsMap;
}
示例6: setAssertHelper
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
private <T> void setAssertHelper(Set<T> s, JSONArray pya) {
Set<T> sorteds = new TreeSet<T> (s);
Set<T> pyset = new TreeSet<T>();
for (int i = 0; i < pya.size(); i++) {
@SuppressWarnings("unchecked")
T val = ((T) pya.get(i));
pyset.add(val);
}
for (T si : sorteds) {
Long sil = ((Number) si).longValue();
assertEquals(true, pyset.contains(sil));
}
}
示例7: CloudantCredential
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
public CloudantCredential () {
//Get VCAP_SERVICES environment varialbe from Bluemix - cloudant service should be bound to this service for
//environment variable to be present
//
//Alternatively - provide a manifest.yml where environment variables are provided
String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
if (VCAP_SERVICES != null) {
try {
System.out.println("vcap is: " + VCAP_SERVICES);
JSONObject vcap = (JSONObject) JSONObject.parse(VCAP_SERVICES);
JSONArray credentials = (JSONArray) vcap.get("cloudantNoSQLDB");
cloudantInstance = (JSONObject) credentials.get(0);
cloudantCredentials = (JSONObject) cloudantInstance.get("credentials");
//System.out.println(cloudantCredentials);
LOGGER.info("username is from VCAP_SERVICES: " + cloudantCredentials.get("username").toString());
LOGGER.info("password is from VCAP_SERVICES: " + (cloudantPassword == null ? "null" : "******"));
//System.out.println(cloudantCredentials.get("password"));
cloudantUsername = cloudantCredentials.get("username").toString();
cloudantPassword = cloudantCredentials.get("password").toString();
cloudantURI = cloudantCredentials.get("url").toString();
} catch (IOException e) {
e.printStackTrace();
}
} else {
//VCAP services does not exist so look for dbUsername, dbPassword and dbURI environment variables
//When running locally - these environment variables need to be defined by user. Values should be
//from a Cloudant service running in Bluemix
cloudantUsername = System.getenv("dbUsername");
LOGGER.info("username is from environment variable dbUsername: " + cloudantUsername);
cloudantPassword = System.getenv("dbPassword");
LOGGER.info("password is from environment variable dbPassword: " + (cloudantPassword == null ? "null" : "*****"));
cloudantURI = System.getenv("dbURI");
}
}
示例8: getMongoInfo
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
public static void getMongoInfo() {
JSONObject vcap_service_obj = null;
String vcap_service_str = System.getenv("VCAP_SERVICES");
System.out.println("vcap_service_str" + vcap_service_str);
if (null != vcap_service_str && vcap_service_str.length() > 0) {
System.out.println("getMongoInfo : found icap_services env var");
try {
vcap_service_obj = JSONObject.parse(vcap_service_str);
System.out.println("vcap_service_obj" + vcap_service_obj);
System.out.println("getting vcap_service_obj details, size:"
+ vcap_service_obj.size());
System.out.println("getting vcap_service_obj keyset:"
+ vcap_service_obj.keySet());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// JSONArray mongo_services = (JSONArray) vcap_service_obj.get("mongodb-2.2");
// JSONObject first_myMongo = (JSONObject) mongo_services.get(0);
// JSONObject first_credential = (JSONObject) first_myMongo
// .get("credentials");
// host = (String) first_credential.get("host");
// System.out.println("host: " + host);
// port = first_credential.get("port").toString();
// databaseName = (String) first_credential.get("db");
// uid = (String) first_credential.get("username");
// pwd = (String) first_credential.get("password");
JSONArray mongo_services = (JSONArray) vcap_service_obj.get("mongolab");
JSONObject first_myMongo = (JSONObject) mongo_services.get(0);
JSONObject first_credential = (JSONObject) first_myMongo
.get("credentials");
uri =(String) first_credential.get("uri");
uri_value = uri.substring(10);
System.out.println("uri_value = " + uri_value);
uid_pwd= uri_value.substring(0,uri_value.indexOf("@"));
host_port_dbname = uri_value.substring(uri_value.indexOf("@") + 1);
uid=uid_pwd.substring(0, uid_pwd.indexOf(":"));
pwd=uid_pwd.substring(uid_pwd.indexOf(":")+1);
System.out.println("uid = " + uid);
System.out.println("pwd = " + pwd);
host_port= host_port_dbname.substring(0, host_port_dbname.indexOf("/"));
databaseName = host_port_dbname.substring(host_port_dbname.indexOf("/")+1);
System.out.println("databaseName = " + databaseName);
host = host_port.substring(0, host_port.indexOf(":"));
port = host_port.substring(host_port.indexOf(":")+1);
System.out.println("host = " + host);
System.out.println("port = " + port);
}
示例9: getSecurityEndpoints
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
public final static String[] getSecurityEndpoints() {
String[] securityEndpoints = new String[3];
String vcap_services = System.getenv("VCAP_SERVICES");
System.out.println("vcap_services is " + vcap_services);
JSONObject vcap_service_obj = null;
try {
vcap_service_obj = JSONObject.parse(vcap_services);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONArray security_services = (JSONArray) vcap_service_obj
.get(SECURITYNAME);
System.out.println("security_services is "
+ security_services.toString());
JSONObject first_security = (JSONObject) security_services.get(0);
JSONObject first_credential = (JSONObject) first_security
.get("credentials");
JSONObject authorize = (JSONObject) first_credential.get("authorize");
String authorize_endpoint = (String) authorize.get("endpoint");
System.out.println("authorize_endpoint is " + authorize_endpoint);
JSONObject getAccessToken = (JSONObject) first_credential
.get("getAccessToken");
String getAccessToken_endpoint = (String) getAccessToken
.get("endpoint");
System.out.println("getAccessToken_endpoint is "
+ getAccessToken_endpoint);
JSONObject checkToken = (JSONObject) first_credential.get("checkToken");
String checkToken_endpoint = (String) checkToken.get("endpoint");
System.out.println("checkToken_endpoint is " + checkToken_endpoint);
securityEndpoints[0] = getAccessToken_endpoint;
securityEndpoints[1] = authorize_endpoint;
securityEndpoints[2] = checkToken_endpoint;
return securityEndpoints;
}
示例10: getSecurityEndpoints
import com.ibm.json.java.JSONArray; //导入方法依赖的package包/类
public final static String[] getSecurityEndpoints() {
String[] securityEndpoints = new String[3];
String vcap_services = System.getenv("VCAP_SERVICES");
System.out.println("vcap_services is " + vcap_services);
JSONObject vcap_service_obj = null;
try {
vcap_service_obj = JSONObject.parse(vcap_services);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONArray security_services = (JSONArray) vcap_service_obj
.get(SECURITYNAME);
System.out.println("security_services is "
+ security_services.toString());
JSONObject first_security = (JSONObject) security_services.get(0);
JSONObject first_credential = (JSONObject) first_security
.get("credentials");
JSONObject authorize = (JSONObject) first_credential.get("authorize");
String authorize_endpoint = (String) authorize.get("endpoint");
System.out.println("authorize_endpoint is " + authorize_endpoint);
JSONObject getAccessToken = (JSONObject) first_credential
.get("getAccessToken");
String getAccessToken_endpoint = (String) getAccessToken
.get("endpoint");
System.out.println("getAccessToken_endpoint is "
+ getAccessToken_endpoint);
JSONObject checkToken = (JSONObject) first_credential.get("checkToken");
String checkToken_endpoint = (String) checkToken.get("endpoint");
System.out.println("checkToken_endpoint is " + checkToken_endpoint);
securityEndpoints[0] = getAccessToken_endpoint;
securityEndpoints[1] = authorize_endpoint;
securityEndpoints[2] = checkToken_endpoint;
return securityEndpoints;
}