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


Java JSONObject.put方法代码示例

本文整理汇总了Java中com.ibm.json.java.JSONObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.put方法的具体用法?Java JSONObject.put怎么用?Java JSONObject.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.ibm.json.java.JSONObject的用法示例。


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

示例1: 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);

}
 
开发者ID:IBMStreams,项目名称:streamsx.avro,代码行数:27,代码来源:JSONBeacon.java

示例2: 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;
}
 
开发者ID:IBM-Cloud,项目名称:talent-manager,代码行数:17,代码来源:WatsonUserModeller.java

示例3: addToJson

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
/**
 * Helper method to add the device info to an existing JSON Object
 *
 * @param payload an existing JSON Object
 * @return JSON Object with the device information added
 */
protected JSONObject addToJson(JSONObject payload) {
    // this is to ensure we do not overwrite the device descriptor when we are updating a document
    if (payload.get(JSON_DEVICE_DESCRIPTOR) == null) {
        payload.put(JSON_DEVICE_DESCRIPTOR, mDeviceDescriptor);
    }
    if (mName != null) {
        payload.put(JSON_NAME, mName);
    }
    if (mRegistrationType != null) {
        payload.put(JSON_REGISTRATION_TYPE, mRegistrationType);
    }
    if (mData != null) {
        payload.put(JSON_DATA, mData);
    }
    if (mUnencryptedData != null) {
        payload.put(JSON_UNENCRYPTED_DATA, mUnencryptedData);
    }
    payload.put(JSON_REGISTERED, mRegistered);
    payload.put(JSON_BLACKLIST, mBlacklisted);

    return payload;
}
 
开发者ID:presence-insights,项目名称:pi-clientsdk-android,代码行数:29,代码来源:PIDeviceInfo.java

示例4: 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;
}
 
开发者ID:presence-insights,项目名称:pi-clientsdk-android,代码行数:23,代码来源:PIBeaconSensorService.java

示例5: 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;
  }
 
开发者ID:presence-insights,项目名称:pi-clientsdk-android,代码行数:29,代码来源:PIBeaconData.java

示例6: testDeserializeArray

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
/**
 * Test that if the serialized value is
 * an array, it ends up wrapped in an object.
 */
@Test
public void testDeserializeArray() throws Exception {
    final String data = "[ 100, 500, false, 200, 400 ]";
    final Topology t = new Topology();
    TStream<String> array = t.strings(data);

    TStream<JSONObject> json = JSONStreams.deserialize(array);
    TStream<String> jsonString = JSONStreams.serialize(json);
    
    JSONArray ja = (JSONArray) JSON.parse(data);
    JSONObject jo = new JSONObject();
    jo.put("payload", ja);

    checkJsonOutput(jo, jsonString);
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:20,代码来源:JSONStreamsTest.java

示例7: toTuple

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
public static OutputTuple toTuple(DeviceCmd cmd, OutputTuple tuple) {
    
    tuple.setString(Schemas.TYPE_ID, cmd.getDevice().getTypeId());
    tuple.setString(Schemas.DEVICE_ID, cmd.getDevice().getId());
    tuple.setString(Schemas.CMD_ID, cmd.getCmdId());
    
    
    JSONObject payload = new JSONObject();
    payload.put("d", cmd.getData()); //$NON-NLS-1$
    
    Instant ts = cmd.getTs();
    
    if (ts == null)
        ts = Instant.now();        
    payload.put("ts", ts.toString()); //$NON-NLS-1$
    
    try {
        tuple.setString(Schemas.JSON_STRING, payload.serialize());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return tuple;
}
 
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:24,代码来源:IotUtils.java

示例8: generateStatuses

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
public static JSONObject[] generateStatuses(int count) {
    Random r = new Random();
    JSONObject[] statuses = new JSONObject[count];
    
    for (int i = 0 ; i < count ; i++) {
        JSONObject status = new JSONObject();
        
        statuses[i] = status;
        
        status.put("py_type", "T" + r.nextInt(4));
        status.put("py_device", "D" + r.nextInt(10));
        
        JSONObject payload = new JSONObject();
        status.put("py_payload", payload);
        payload.put("s1", (long) r.nextInt(1000));
        payload.put("s2", "S2_" + r.nextInt(5000));
    }
    
    return statuses;
}
 
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:21,代码来源:DeviceStatusTest.java

示例9: generateEvents

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
public static JSONObject[] generateEvents(int count) {
    Random r = new Random();
    JSONObject[] events = new JSONObject[count];
    
    for (int i = 0 ; i < count ; i++) {
        JSONObject event = new JSONObject();
        
        events[i] = event;
        
        event.put("py_type", "T" + r.nextInt(4));
        event.put("py_device", "D" + r.nextInt(10));
        event.put("py_event", "E" + r.nextInt(5));
        
        if (r.nextFloat() > 0.1) {
            int offset = r.nextInt(20000) - 10000;
            event.put("py_ts", System.currentTimeMillis() + offset);
        }
        
        JSONObject payload = new JSONObject();
        event.put("py_data", payload);
        payload.put("v1", (long) r.nextInt(1000));
        payload.put("v2", "V2_" + r.nextInt(5000));
    }
    
    return events;
}
 
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:27,代码来源:DeviceEventsTest.java

示例10: generateCommands

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
public static JSONObject[] generateCommands(int count) {
    Random r = new Random();
    JSONObject[] commands = new JSONObject[count];
    
    for (int i = 0 ; i < count ; i++) {
        JSONObject cmd = new JSONObject();
        
        commands[i] = cmd;
        
        cmd.put("py_type", "T" + r.nextInt(4));
        cmd.put("py_device", "D" + r.nextInt(10));
        cmd.put("py_command", "C" + r.nextInt(5));
        
        if (r.nextFloat() > 0.1) {
            int offset = r.nextInt(20000) - 10000;
            cmd.put("py_ts", System.currentTimeMillis() + offset);
        }
        
        JSONObject data = new JSONObject();
        cmd.put("py_data", data);
        data.put("c1", (long) r.nextInt(1000));
        data.put("c2", "C2_" + r.nextInt(5000));
    }
    
    return commands;
}
 
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:27,代码来源:DeviceCommandsTest.java

示例11: testModifyingJson

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
@Test
public void testModifyingJson() throws Exception {
    final Topology t = new Topology();

    final JSONObject value = new JSONObject();
    value.put("question",QUESTION);
    TStream<JSONObject> s = t.constants(Collections.singletonList(value));

    TStream<String> jsonString = JSONStreams.serialize(s);
    TStream<JSONObject> json = JSONStreams.deserialize(jsonString);

    TStream<JSONObject> jsonm = modifyJSON(json);

    assertFalse(value.containsKey("answer"));
    JSONObject ev = new JSONObject();
    ev.put("question", QUESTION);
    ev.put("answer", 42l);

    checkJsonOutput(ev, JSONStreams.serialize(jsonm));
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:21,代码来源:JSONStreamsTest.java

示例12: testJSONAble

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
@Test
public void testJSONAble() throws IOException, Exception {
    Topology topology = new Topology();
    
    final TestJSONAble value = new TestJSONAble(42,QUESTION);
    TStream<TestJSONAble> s = topology.constants(
            Collections.singletonList(value)).asType(TestJSONAble.class);

    TStream<JSONObject> js = JSONStreams.toJSON(s);
    
    JSONObject ev = new JSONObject();
    ev.put("b", QUESTION);
    ev.put("a", 42l);

    checkJsonOutput(ev, JSONStreams.serialize(js));
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:17,代码来源:JSONStreamsTest.java

示例13: testFlatten

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
@Test
public void testFlatten() throws Exception {
    final Topology t = new Topology();

    final JSONObject value = new JSONObject();
    final JSONArray array = new JSONArray();
    JSONObject e1 = new JSONObject(); e1.put("val", "hello"); array.add(e1);
    JSONObject e2 = new JSONObject(); e2.put("val", "goodbye"); array.add(e2);
    JSONObject e3 = new JSONObject(); e3.put("val", "farewell"); array.add(e3);
    value.put("greetings", array);
    
    List<JSONObject> inputs = new ArrayList<>();
    inputs.add(value);
    inputs.add(new JSONObject()); // no list present
    
    JSONObject emptyList = new JSONObject();
    emptyList.put("greetings", new JSONArray());
    inputs.add(emptyList);
    
    TStream<JSONObject> s = t.constants(inputs);

    TStream<JSONObject> jsonm = JSONStreams.flattenArray(s, "greetings");
    TStream<String> output = JSONStreams.serialize(jsonm);
           
    completeAndValidate(output, 10,  e1.toString(), e2.toString(), e3.toString());
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:27,代码来源:JSONStreamsTest.java

示例14: 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();
}
 
开发者ID:IBM,项目名称:MaximoForgeViewerPlugin,代码行数:43,代码来源:ResultAuthentication.java

示例15: Builder

import com.ibm.json.java.JSONObject; //导入方法依赖的package包/类
public Builder(String index, String type, boolean enabled) {
    this.index = index;
    this.type = type;
    
    JSONObject enabledTrue = new JSONObject();
    enabledTrue.put(ENABLED_PROPERTY, enabled);
    
    JSONObject sizeMapping = new JSONObject();
    sizeMapping.put(SIZE_ATTR, enabledTrue);
    
    this.source = sizeMapping;
}
 
开发者ID:IBMStreams,项目名称:streamsx.elasticsearch,代码行数:13,代码来源:SizeMapping.java


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