本文整理汇总了Java中com.ibm.json.java.JSON类的典型用法代码示例。如果您正苦于以下问题:Java JSON类的具体用法?Java JSON怎么用?Java JSON使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSON类属于com.ibm.json.java包,在下文中一共展示了JSON类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: string2JSON
import com.ibm.json.java.JSON; //导入依赖的package包/类
public static JSONArtifact string2JSON(
String data
) {
if( data == null || data.length() == 0 )
{
return null;
}
JSONArtifact jArtifact;
try
{
jArtifact = JSON.parse( data );
}
catch( Throwable t )
{
return null; // Not JSON
}
return jArtifact;
}
开发者ID:IBM,项目名称:MaximoForgeViewerPlugin,代码行数:20,代码来源:Result.java
示例2: readHostnameFromVcapEnvironment
import com.ibm.json.java.JSON; //导入依赖的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;
}
开发者ID:WASdev,项目名称:sample.consulservicediscovery,代码行数:20,代码来源:Endpoint.java
示例3: assertMatchingEvents
import com.ibm.json.java.JSON; //导入依赖的package包/类
private void assertMatchingEvents(JSONObject[] events, List<String> results) throws Exception {
assertEquals(events.length, results.size());
for (int i = 0 ; i < events.length; i++) {
JSONObject event = events[i];
JSONObject result = (JSONObject) JSON.parse(results.get(i));
assertEquals(event.get("py_type"), result.get("typeId"));
assertEquals(event.get("py_device"), result.get("deviceId"));
assertEquals(event.get("py_event"), result.get("eventId"));
assertEquals(event.get("py_data"), result.get("d"));
if (event.containsKey("py_ts")) {
assertTrue(result.containsKey("ts"));
Instant expectedTs = Instant.ofEpochMilli((Long) event.get("py_ts"));
assertEquals(expectedTs, Instant.parse((String) result.get("ts")));
} else {
assertFalse(result.containsKey("ts"));
}
}
}
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:23,代码来源:DeviceEventsTest.java
示例4: assertMatchingCommands
import com.ibm.json.java.JSON; //导入依赖的package包/类
private void assertMatchingCommands(JSONObject[] cmds, List<String> results) throws Exception {
assertEquals(cmds.length, results.size());
for (int i = 0 ; i < cmds.length; i++) {
JSONObject cmd = cmds[i];
JSONObject result = (JSONObject) JSON.parse(results.get(i));
System.err.println("CMD :" + cmd);
System.err.println("RESULT:" + result);
assertEquals(cmd.get("py_command"), result.get("cmdId"));
assertEquals(cmd.get("py_data"), result.get("d"));
assertTrue(result.containsKey("ts"));
}
}
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:18,代码来源:WatsonDeviceCommandsTest.java
示例5: assertMatchingCommands
import com.ibm.json.java.JSON; //导入依赖的package包/类
private void assertMatchingCommands(JSONObject[] cmds, List<String> results) throws Exception {
assertEquals(cmds.length, results.size());
for (int i = 0 ; i < cmds.length; i++) {
JSONObject cmd = cmds[i];
JSONObject result = (JSONObject) JSON.parse(results.get(i));
assertEquals(cmd.get("py_type"), result.get("typeId"));
assertEquals(cmd.get("py_device"), result.get("deviceId"));
assertEquals(cmd.get("py_command"), result.get("cmdId"));
assertEquals(cmd.get("py_data"), result.get("d"));
if (cmd.containsKey("py_ts")) {
assertTrue(result.containsKey("ts"));
Instant expectedTs = Instant.ofEpochMilli((Long) cmd.get("py_ts"));
assertEquals(expectedTs, Instant.parse((String) result.get("ts")));
} else {
assertFalse(result.containsKey("ts"));
}
}
}
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:23,代码来源:DeviceCommandsTest.java
示例6: toSPL
import com.ibm.json.java.JSON; //导入依赖的package包/类
/**
* Convert a JSON stream to an SPLStream.
* @param stream JSON stream to be converted.
* @return SPLStream with schema {@link JSONSchemas#JSON}.
*/
public static SPLStream toSPL(TStream<JSONObject> stream) {
return SPLStreams.convertStream(stream,
new BiFunction<JSONObject, OutputTuple, OutputTuple>() {
private static final long serialVersionUID = 1L;
@Override
public OutputTuple apply(JSONObject v1, OutputTuple v2) {
try {
v2.setString(0, v1.serialize());
return v2;
} catch (IOException e) {
return null;
}
}
}, JSONSchemas.JSON);
}
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:23,代码来源:JSONStreams.java
示例7: testDeserializeArray
import com.ibm.json.java.JSON; //导入依赖的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
示例8: testJsonSPL
import com.ibm.json.java.JSON; //导入依赖的package包/类
@Test
public void testJsonSPL() throws Exception {
final Topology t = new Topology();
TStream<String> example = t.strings(JSON_EXAMPLE);
TStream<JSONObject> json = JSONStreams.deserialize(example);
SPLStream spl = JSONStreams.toSPL(json);
assertEquals(JSONSchemas.JSON, spl.getSchema());
TStream<JSONObject> jsonFromSPL = spl.toJSON();
assertEquals(JSONObject.class, jsonFromSPL.getTupleClass());
assertEquals(JSONObject.class, jsonFromSPL.getTupleType());
TStream<String> jsonString = JSONStreams.serialize(jsonFromSPL);
checkJsonOutput(JSON.parse(JSON_EXAMPLE), jsonString);
}
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:19,代码来源:JSONStreamsTest.java
示例9: assertMatchingStatuses
import com.ibm.json.java.JSON; //导入依赖的package包/类
private void assertMatchingStatuses(JSONObject[] statuses, List<String> results) throws Exception {
assertEquals(statuses.length, results.size());
for (int i = 0 ; i < statuses.length; i++) {
JSONObject status = statuses[i];
JSONObject result = (JSONObject) JSON.parse(results.get(i));
assertEquals(status.get("py_type"), result.get("typeId"));
assertEquals(status.get("py_device"), result.get("deviceId"));
assertEquals(status.get("py_payload"), result.get("payload"));
}
}
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:14,代码来源:DeviceStatusTest.java
示例10: assertMatchingEvents
import com.ibm.json.java.JSON; //导入依赖的package包/类
private void assertMatchingEvents(JSONObject[] events, List<String> results) throws Exception {
assertEquals(events.length, results.size());
for (int i = 0 ; i < events.length; i++) {
JSONObject event = events[i];
JSONObject result = (JSONObject) JSON.parse(results.get(i));
assertEquals(event.get("py_event"), result.get("eventId"));
assertEquals(event.get("py_data"), result.get("d"));
assertTrue(result.containsKey("ts"));
}
}
开发者ID:IBMStreams,项目名称:streamsx.iot,代码行数:15,代码来源:WatsonDeviceEventsTest.java
示例11: apply
import com.ibm.json.java.JSON; //导入依赖的package包/类
@Override
public JSONObject apply(String tuple) {
try {
JSONArtifact artifact = JSON.parse(tuple);
if (artifact instanceof JSONObject)
return (JSONObject) artifact;
JSONObject wrapper = new JSONObject();
wrapper.put(PAYLOAD, artifact);
return wrapper;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:14,代码来源:JSONStreams.java
示例12: getConnection
import com.ibm.json.java.JSON; //导入依赖的package包/类
private static Connection getConnection() throws Exception {
Map<String, String> env = System.getenv();
if (env.containsKey("VCAP_SERVICES")) {
// we are running on cloud foundry, let's grab the service details from vcap_services
JSONObject vcap = (JSONObject) JSON.parse(env.get("VCAP_SERVICES"));
JSONObject service = null;
// We don't know exactly what the service is called, but it will contain "elephantsql"
for (Object key : vcap.keySet()) {
String keyStr = (String) key;
if (keyStr.toLowerCase().contains("elephantsql")) {
service = (JSONObject) ((JSONArray) vcap.get(keyStr)).get(0);
break;
}
}
if (service != null) {
JSONObject creds = (JSONObject) service.get("credentials");
URI uri = URI.create((String) creds.get("uri"));
String url = "jdbc:postgresql://" + uri.getHost() + ":" + uri.getPort() + uri.getPath();
String username = uri.getUserInfo().split(":")[0];
String password = uri.getUserInfo().split(":")[1];
return DriverManager.getConnection(url, username, password);
}
}
throw new Exception("No ElephantSQL service URL found. Make sure you have bound the correct services to your app.");
}
开发者ID:ibmjstart,项目名称:bluemix-java-postgresql-uploader,代码行数:30,代码来源:ElephantSQLClient.java
示例13: testSimpleJson
import com.ibm.json.java.JSON; //导入依赖的package包/类
/**
* Convert an example JSON as a String back to a String through JSON
* deserialization and serialization.
*/
@Test
public void testSimpleJson() throws Exception {
final Topology t = new Topology("SimpleJson");
TStream<String> example = t.strings(JSON_EXAMPLE);
TStream<JSONObject> json = JSONStreams.deserialize(example);
assertEquals(JSONObject.class, json.getTupleClass());
assertEquals(JSONObject.class, json.getTupleType());
TStream<String> jsonString = JSONStreams.serialize(json);
assertEquals(String.class, jsonString.getTupleClass());
assertEquals(String.class, jsonString.getTupleType());
checkJsonOutput(JSON.parse(JSON_EXAMPLE), jsonString);
}
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:24,代码来源:JSONStreamsTest.java
示例14: checkJsonOutput
import com.ibm.json.java.JSON; //导入依赖的package包/类
private JSONArtifact checkJsonOutput(JSONArtifact expected,
TStream<String> jsonString) throws Exception, IOException {
assertEquals(String.class, jsonString.getTupleClass());
assertEquals(String.class, jsonString.getTupleType());
SPLStream splS = SPLStreams.stringToSPLStream(jsonString);
MostRecent<Tuple> mr = jsonString.topology().getTester()
.splHandler(splS, new MostRecent<Tuple>());
Condition<Long> singleTuple = jsonString.topology().getTester().tupleCount(splS, 1);
complete(jsonString.topology().getTester(), singleTuple, 10, TimeUnit.SECONDS);
JSONArtifact rv = JSON.parse(mr.getMostRecentTuple().getString(0));
assertEquals(expected, rv);
return rv;
}
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:22,代码来源:JSONStreamsTest.java
注:本文中的com.ibm.json.java.JSON类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论