本文整理汇总了Java中com.ibm.json.java.JSONObject类的典型用法代码示例。如果您正苦于以下问题:Java JSONObject类的具体用法?Java JSONObject怎么用?Java JSONObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONObject类属于com.ibm.json.java包,在下文中一共展示了JSONObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getComments
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
private JSONArray getComments(String itemNumber) {
JSONArray returnArray = new JSONArray();
CouchDbConnector dbc = _db.createConnector(dbname, true);
Map<String, String> doc = new HashMap<String, String>();
ViewQuery query = new ViewQuery().allDocs().includeDocs(true);
List<Map> result = dbc.queryView(query, Map.class);
JSONArray jsonresult = new JSONArray();
for (Map element : result) {
JSONObject obj = new JSONObject();
obj.putAll(element);
if(itemNumber==null || obj.get("itemNumber").equals(itemNumber))
jsonresult.add(obj);
}
System.out.println(jsonresult.toString());
return jsonresult;
}
示例2: PIBeacon
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
public PIBeacon(JSONObject beaconObj) {
JSONObject geometry = (JSONObject)beaconObj.get("geometry");
JSONObject properties = (JSONObject)beaconObj.get("properties");
code = (String) properties.get(JSON_CODE);
name = (String) properties.get(JSON_NAME);
description = properties.get(JSON_DESCRIPTION) != null ? (String)properties.get(JSON_DESCRIPTION) : "";
proximityUUID = (String) properties.get(JSON_PROXIMITY_UUID);
major = (String) properties.get(JSON_MAJOR);
minor = (String) properties.get(JSON_MINOR);
threshold = objToDouble(properties.get(JSON_THRESHOLD));
JSONArray coordinates = (JSONArray) geometry.get("coordinates");
x = objToDouble(coordinates.get(0));
y = objToDouble(coordinates.get(1));
}
示例3: Scene
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
private Scene(
JSONObject jObj
) {
if( jObj == null ) return;
Object value = jObj.get( KEY_NAME );
if( value != null && value instanceof String )
{
_name = (String)value;
}
value = jObj.get( KEY_GUID );
if( value != null && value instanceof String )
{
_guid = (String)value;
}
}
示例4: getNLUOutput
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
/**
* Invoke NLU to extract keywords (entities)
*
* @param text Text document from which personal data needs to be extracted
* @return response.toString() NLU output as a String
*/
private JSONObject getNLUOutput(String text) throws Exception {
try {
Map<String, String> nluCreds = getNLUCredentials();
// String user = System.getenv("username");
// String password = System.getenv("password");
String model = System.getenv("wks_model");
// if (logger.isInfoEnabled()) {
// logger.info("NLU Instance details");
// logger.info("user: " + user + ", modelid: " + model + " For password, refer env variables");
// }
NaturalLanguageUnderstanding service = new NaturalLanguageUnderstanding(
NaturalLanguageUnderstanding.VERSION_DATE_2017_02_27, nluCreds.get("username"), nluCreds.get("password"));
EntitiesOptions entitiesOptions = new EntitiesOptions.Builder().model(model).emotion(true).sentiment(true)
.limit(20).build();
KeywordsOptions keywordsOptions = new KeywordsOptions.Builder().emotion(true).sentiment(true).limit(20)
.build();
Features features = new Features.Builder().entities(entitiesOptions).keywords(keywordsOptions).build();
AnalyzeOptions parameters = new AnalyzeOptions.Builder().text(text).features(features).build();
AnalysisResults response = service.analyze(parameters).execute();
return JSONObject.parse(response.toString());
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e.getMessage());
}
}
示例5: process
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
@Override
protected void process() throws Exception {
final StreamingOutput<OutputTuple> out = getOutput(0);
JSONObject json = new JSONObject();
for (int i = 0; i < 100; i++) {
json.put("username", "Frank");
json.put("tweet", "This JSON message also rocks: " + i);
json.put("timestamp", new Long(1048298240L + i));
/* Now submit tuple */
OutputTuple tuple = out.newTuple();
String jsonString = json.serialize();
long timeStamp = System.currentTimeMillis();
tuple.setString(0, jsonString);
tuple.setLong(1, timeStamp);
out.submit(tuple);
if (i != 0 && i % 20 == 0)
out.punctuate(Punctuation.WINDOW_MARKER);
}
// Make the set of tuples a window.
out.punctuate(Punctuation.WINDOW_MARKER);
}
示例6: formatTree
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
private static void formatTree(JSONObject node, int level, List<Map<String,String>> arr) {
if (node == null) return;
JSONArray children = (JSONArray)node.get("children");
if (level > 0 && (children == null || level != 2)) {
Map<String,String> obj = new HashMap<String,String>();
obj.put("id", (String)node.get("id"));
if (children != null) obj.put("title", "true");
if (node.containsKey("percentage")) {
double p = (Double)node.get("percentage");
p = Math.floor(p * 100.0);
obj.put("value", Double.toString(p) + "%");
}
arr.add(obj);
}
if (children != null && !"sbh".equals(node.get("id"))) {
for (int i = 0; i < children.size(); i++) {
formatTree((JSONObject)children.get(i), level + 1, arr);
}
}
}
示例7: buildContent
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
private JSONObject buildContent(String text)
{
JSONObject contentItem = new JSONObject();
contentItem.put("userid", UUID.randomUUID().toString());
contentItem.put("id", UUID.randomUUID().toString());
contentItem.put("sourceid", "freetext");
contentItem.put("contenttype", "text/plain");
contentItem.put("language", "en");
contentItem.put("content", text);
JSONObject content = new JSONObject();
JSONArray contentItems = new JSONArray();
content.put("contentItems", contentItems);
contentItems.add(contentItem);
return content;
}
示例8: readHostnameFromVcapEnvironment
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
private static String readHostnameFromVcapEnvironment() {
String vcapApplication = System.getenv().get("VCAP_APPLICATION");
if (vcapApplication != null) {
try {
JSONObject p = (JSONObject) JSON.parse(vcapApplication);
JSONArray uris = (JSONArray) p.get("application_uris");
// Take the first uri
if (uris != null) {
return (String) uris.iterator().next();
}
} catch (IOException e) {
// Let's log and ignore this case and drop through to the
// default case
e.printStackTrace();
}
}
return null;
}
示例9: getSecretData
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
@GET
@Path("/{user_id}/secret")
@Produces(MediaType.APPLICATION_JSON)
@OAuthSecurity(scope="AdapterAuthenticationRealm")
public Response getSecretData(@PathParam("user_id") String userId) {
OAuthSecurityContext securityContext = api.getSecurityAPI().getSecurityContext();
OAuthUserIdentity identity = securityContext.getUserIdentity();
JSONObject response = new JSONObject();
response.put("secretData", "This is the secret Data...");
if (identity != null) {
response.put("userIdentity", identity.toString());
}
return Response.ok(response).build();
}
示例10: getDeviceByDescriptor
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
/**
* Retrieves a device within an organization by its descriptor.
*
* @param deviceDescriptor unique identifier for the device.
* @param completionHandler callback for APIs asynchronous calls. Result returns as {@link PIDevice PIDevice}.
*
* @deprecated use {@link #getDevice(String, PIAPICompletionHandler)}. When you register a device,
* the method will return a PIDevice object that contains the device documents code.
*/
@Deprecated
public void getDeviceByDescriptor(String deviceDescriptor, final PIAPICompletionHandler completionHandler) {
String device = String.format("%s/tenants/%s/orgs/%s/devices?rawDescriptor=%s", mServerURL, mTenantCode, mOrgCode, deviceDescriptor);
try {
URL url = new URL(device);
GET(url, new PIAPICompletionHandler() {
@Override
public void onComplete(PIAPIResult result) {
if (result.getResponseCode() == 200) {
JSONArray matchingDevices = (JSONArray)result.getResultAsJson().get(JSON_ROWS);
if (matchingDevices.size() > 0) {
result.setResult(new PIDevice((JSONObject) matchingDevices.get(0)));
}
}
completionHandler.onComplete(result);
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
示例11: testBeaconTuples
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
@Test
public void testBeaconTuples() throws Exception {
// Uses IBM JSON4J
assumeTrue(hasStreamsInstall());
final int count = new Random().nextInt(1000) + 37;
Topology topology = newTopology();
TStream<BeaconTuple> beacon = BeaconStreams.beacon(topology, count);
TStream<JSONObject> json = JSONStreams.toJSON(beacon);
TStream<String> strings = JSONStreams.serialize(json);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(strings, count);
Condition<String> contents = createPredicate(strings, tester);
complete(tester, expectedCount, 20, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(contents.toString(), contents.valid());
}
示例12: PIDevice
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
public PIDevice(JSONObject deviceObj) {
code = (String) deviceObj.get(JSON_CODE);
descriptor = (String) deviceObj.get(JSON_DESCRIPTOR);
registered = (Boolean) deviceObj.get(JSON_REGISTERED);
if (registered) {
name = (String) deviceObj.get(JSON_NAME);
descriptorType = (String) deviceObj.get(JSON_DESCRIPTOR_TYPE);
registrationType = (String) deviceObj.get(JSON_REGISTRATION_TYPE);
data = (JSONObject) deviceObj.get(JSON_DATA);
unencryptedData = (JSONObject) deviceObj.get(JSON_UNENCRYPTED_DATA);
blacklisted = (Boolean) deviceObj.get(JSON_BLACKLIST);
if (deviceObj.containsKey(JSON_AUTOBLACKLIST)) {
autoblacklisted = (Boolean) deviceObj.get(JSON_AUTOBLACKLIST);
}
}
}
示例13: sendBeaconNotification
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
private void sendBeaconNotification(Collection<Beacon> beacons) {
PILogger.d(TAG, "sending beacon notification message");
JSONObject payload = buildBeaconPayload(beacons);
mPiApiAdapter.sendBeaconNotificationMessage(payload, new PIAPICompletionHandler() {
@Override
public void onComplete(PIAPIResult result) {
if (result.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
PILogger.e(TAG, result.toString());
}
}
});
// send beacons in range event to listener callback
Intent intent = new Intent(PIBeaconSensor.INTENT_RECEIVER_BEACON_COLLECTION);
intent.putParcelableArrayListExtra(PIBeaconSensor.INTENT_EXTRA_BEACONS_IN_RANGE, new ArrayList<Beacon>(beacons));
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
示例14: buildBeaconPayload
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
private JSONObject buildBeaconPayload(Collection<Beacon> beacons) {
long detectedTime = System.currentTimeMillis();
JSONObject payload = new JSONObject();
JSONArray beaconArray = new JSONArray();
// build payload with nearest beacon only
Beacon nearestBeacon = beacons.iterator().next();
for (Beacon b : beacons) {
if (b.getDistance() < nearestBeacon.getDistance()) {
nearestBeacon = b;
}
}
PIBeaconData data = new PIBeaconData(nearestBeacon);
data.setDetectedTime(detectedTime);
data.setDeviceDescriptor(mDeviceDescriptor);
beaconArray.add(data.getBeaconAsJson());
payload.put("bnm", beaconArray);
return payload;
}
示例15: getBeaconAsJson
import com.ibm.json.java.JSONObject; //导入依赖的package包/类
/**
* Helper method to provide the class as a JSON Object
*
* @return JSON Object of the beacon's data
*/
public JSONObject getBeaconAsJson() {
try {
beaconValidator(this);
} catch (Exception e) {
Log.e("ERROR", e.toString());
e.printStackTrace();
}
JSONObject returnObj = new JSONObject();
JSONObject beaconData = new JSONObject();
beaconData.put("proximityUUID", proximityUUID);
beaconData.put("major", major);
beaconData.put("minor", minor);
beaconData.put("accuracy", accuracy);
beaconData.put("rssi", rssi);
beaconData.put("proximity", proximity);
returnObj.put("data", beaconData);
returnObj.put("descriptor", deviceDescriptor);
returnObj.put("detectedTime", detectedTime);
return returnObj;
}