本文整理汇总了Java中com.ibm.json.java.JSONObject.toString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.toString方法的具体用法?Java JSONObject.toString怎么用?Java JSONObject.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.json.java.JSONObject
的用法示例。
在下文中一共展示了JSONObject.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthTokenJSOM
import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
/**
* {"token_type":"Bearer","expires_in":7200,"access_token":"Qdl8N6KPoyfAX3Lumtgia6leqacd"}
* @return
*/
public String getAuthTokenJSOM()
{
JSONObject jobj = new JSONObject();
jobj.put( KEY_TOKEN_TYPE, _token_type );
if( isError() )
{
jobj.put( "ErrorMessage", getErrorMessage() );
String errorType = "";
switch( getErrorType() )
{
case NONE:
errorType = "None";
break;
case HTTP:
errorType = "HTTP";
break;
case REST:
errorType = "REST";
break;
case API:
errorType = "API";
break;
case EXCEPTION:
errorType = "EXCEPTION";
break;
}
jobj.put( "ErrorType", errorType );
jobj.put( "ErrorCode", getErrorCode());
}
else
{
jobj.put( KEY_TOKEN_TYPE, _token_type );
jobj.put( KEY_EXPIRES_IN, "" + _expires_in );
jobj.put( KEY_ACCESS_TOKEN, _access_token );
}
return jobj.toString();
}
示例2: toJson
import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
private static String toJson(Message m) {
JSONObject jo = new JSONObject();
jo.put("key", m.getKey());
jo.put("message", m.getMessage());
jo.put("topic", m.getTopic());
return jo.toString();
}
示例3: bucketCreate
import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
/**
* Use this API to create a bucket. Buckets are arbitrary spaces created and owned by services. Bucket
* keys are unique within the data center or region in which they were created. The service creating
* the bucket is the owner of the bucket, and the owning service will always have full access to a bucket.
* A bucket key cannot be changed once it is created.
* <p>
* Buckets must have a retention policy attached to them at create time. Policy options are:
* Transient,
* Temporary,
* Persistent
* @param bucketKey A unique name you assign to a bucket. It must be globally unique across
* all applications and regions, otherwise the call will fail. Possible
* values: -_.a-z0-9 (between 3-128 characters in length). Note that you cannot
* change a bucket key.
* @param policy
* @param region The region where the bucket resides Acceptable values: US, EMEA Default: US
* @return
* @throws IOException
* @throws URISyntaxException
*/
public ResultCreateBucket bucketCreate(
String bucketKey,
String policy,
String region
)
throws IOException,
URISyntaxException
{
String scope[] = { SCOPE_BUCKET_CREATE };
ResultAuthentication authResult = authenticate( scope );
if( authResult.isError() )
{
return new ResultCreateBucket( authResult );
}
JSONObject j_bucket = new JSONObject();
j_bucket.put( KEY_BUCKETKEY, bucketKey.toLowerCase() );
j_bucket.put( KEY_POLICY_KEY, policy );
String jStr = j_bucket.toString();
String frag = makeURN( API_OSS, PATT_BUCKET, null );
URI uri = new URI( _protocol, null, lookupHostname(), _port, frag , null, null );
URL url = new URL( uri.toASCIIString() );
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
if( region != null && region.length() > 0 )
{
connection.setRequestProperty( "x-ads-region", region );
}
connection.setRequestMethod( "POST" );
authResult.setAuthHeader( connection );
connection.setRequestProperty( "Accept", "Application/json" );
connection.setRequestProperty( "Content-Length", "" + jStr.length() );
connection.setRequestProperty( "Content-Type", "application/json; charset=utf-8" );
connection.setDoOutput( true );
OutputStream os = null;
try
{
os = connection.getOutputStream();
os.write(jStr.getBytes(Charset.forName("UTF-8")));
}
finally
{
if( os != null ) os.close();
}
ResultCreateBucket result = new ResultCreateBucket( connection );
return result;
}
示例4: bucketGrantRightsV2
import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
public Result bucketGrantRightsV2(
String bucketKey,
String serviceId,
String access
)
throws IOException,
URISyntaxException
{
String scope[] = { SCOPE_BUCKET_UPDATE };
ResultAuthentication authResult = authenticate( scope );
if( authResult.isError() )
{
return authResult;
}
/*
{
"allow":[
{"authId":"D6C9x7Bk0vo2HA1qC7l0VHM4MtYqZsN4","access":"full"}
]
}
*/
JSONObject j_rights = new JSONObject();
j_rights.put( "authId", serviceId );
j_rights.put( "access", access );
JSONArray j_serviceList = new JSONArray();
j_serviceList.add( j_rights );
JSONObject j_grantRequest = new JSONObject();
j_grantRequest.put( "allow", j_serviceList );
String jStr = j_grantRequest.toString();
String params[] = { bucketKey.toLowerCase() };
String frag = makeURN( API_OSS, PATT_BUCKET_GRANT2, params );
URI uri = new URI( _protocol, null, lookupHostname(), _port, frag , null, null );
URL url = new URL( uri.toASCIIString() );
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod( "POST" );
authResult.setAuthHeader( connection );
connection.setRequestProperty( "Accept", "Application/json" );
connection.setRequestProperty( "Content-Length", "" + jStr.length() );
connection.setRequestProperty( "Content-Type", "application/json; charset=utf-8" );
connection.setDoOutput( true );
OutputStream os = null;
try
{
os = connection.getOutputStream();
os.write(jStr.getBytes(Charset.forName("UTF-8")));
}
finally
{
if( os != null ) os.close();
}
Result result = new Result( connection );
return result;
}
示例5: bucketRevokeRightsV2
import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
public Result bucketRevokeRightsV2(
String bucketKey,
String serviceId
)
throws IOException,
URISyntaxException
{
String scope[] = { SCOPE_BUCKET_UPDATE };
ResultAuthentication authResult = authenticate( scope );
if( authResult.isError() )
{
return authResult;
}
/*
{
"revoke":[
{"authId":"2s23v1A2uIHPNJQ2nlJjIxYKqAAOInjY"}
]
}
*/
JSONObject j_rights = new JSONObject();
j_rights.put( "authId", serviceId );
JSONArray j_serviceList = new JSONArray();
j_serviceList.add( j_rights );
JSONObject j_grantRequest = new JSONObject();
j_grantRequest.put( "revoke", j_serviceList );
String jStr = j_grantRequest.toString();
String params[] = { bucketKey.toLowerCase() };
String frag = makeURN( API_OSS, PATT_BUCKET_REVOKE2, params );
URI uri = new URI( _protocol, null, lookupHostname(), _port, frag, null, null );
URL url = new URL( uri.toASCIIString() );
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
authResult.setAuthHeader( connection );
connection.setRequestMethod( "POST" );
connection.setRequestProperty( "Content-Type", "application/json; charset=utf-8" );
connection.setDoOutput( true );
OutputStream os = null;
try
{
os = connection.getOutputStream();
os.write(jStr.getBytes(Charset.forName("UTF-8")));
}
finally
{
if( os != null ) os.close();
}
Result result = new Result( connection );
return result;
}