本文整理汇总了Java中org.codehaus.jettison.json.JSONTokener类的典型用法代码示例。如果您正苦于以下问题:Java JSONTokener类的具体用法?Java JSONTokener怎么用?Java JSONTokener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONTokener类属于org.codehaus.jettison.json包,在下文中一共展示了JSONTokener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromJSON
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
public FaunusVertex fromJSON(String line) throws IOException {
try {
final JSONObject json = new JSONObject(new JSONTokener(line));
final FaunusVertex vertex = (FaunusVertex) graphson.vertexFromJson(json);
fromJSONEdges(vertex, json.optJSONArray(_OUT_E), OUT);
json.remove(_OUT_E); // clear up some memory
fromJSONEdges(vertex, json.optJSONArray(_IN_E), IN);
json.remove(_IN_E); // clear up some memory
return vertex;
} catch (Exception e) {
log.error("JSON parse exception", e);
throw new IOException(e.getMessage(), e);
}
}
示例2: handleResponse
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
@Override
public JSONObject handleResponse(HttpResponse response) throws ClientProtocolException,
IOException {
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() >= 300) {
throw new HttpResponseException(statusLine.getStatusCode(),
statusLine.getReasonPhrase());
}
HttpEntity entity = response.getEntity(); // TODO: check entity == null
String json = EntityUtils.toString(entity);
try {
return (JSONObject) new JSONTokener(json).nextValue();
} catch (JSONException e) {
throw new ClientProtocolException("Could not interpret response as JSON", e);
}
}
示例3: handleResponse
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
@Override
public JSONObject handleResponse(final HttpResponse httpResponse) throws IOException {
JSONObject result = null;
if (httpResponse != null) {
StatusLine statusLine = httpResponse.getStatusLine();
switch (statusLine.getStatusCode()) {
case HttpStatus.SC_OK:
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
String json = EntityUtils.toString(entity);
try {
result = (JSONObject) new JSONTokener(json).nextValue();
} catch (JSONException ex) {
throw new ClientProtocolException("Failed to parse JSON", ex);
}
}
break;
default:
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
}
return result;
}
示例4: getAllRepositoryExtendedDataSchemas
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
@Override
public List<SExtendedDataSchema> getAllRepositoryExtendedDataSchemas() throws ServerException, UserException {
try {
List<SExtendedDataSchema> extendedDataSchemas = new ArrayList<SExtendedDataSchema>();
String content = NetUtils.getContent(new URL(getServiceMap().get(SettingsInterface.class).getServiceRepositoryUrl() + "/extendeddataschemas.json"), 5000);
JSONObject root = new JSONObject(new JSONTokener(content));
JSONArray extendedDataSchemasJson = root.getJSONArray("extendeddataschemas");
for (int i = 0; i < extendedDataSchemasJson.length(); i++) {
JSONObject extendedDataSchemaJson = extendedDataSchemasJson.getJSONObject(i);
SExtendedDataSchema sExtendedDataSchema = new SExtendedDataSchema();
sExtendedDataSchema.setName(extendedDataSchemaJson.getString("name"));
sExtendedDataSchema.setContentType(extendedDataSchemaJson.getString("contentType"));
sExtendedDataSchema.setUrl(extendedDataSchemaJson.getString("url"));
sExtendedDataSchema.setDescription(extendedDataSchemaJson.getString("description"));
extendedDataSchemas.add(sExtendedDataSchema);
}
return extendedDataSchemas;
} catch (Exception e) {
return handleException(e);
}
}
示例5: getAllRepositoryModelCheckers
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
@Override
public List<SModelCheckerInstance> getAllRepositoryModelCheckers() throws ServerException, UserException {
requireRealUserAuthentication();
try {
List<SModelCheckerInstance> modelCheckers = new ArrayList<SModelCheckerInstance>();
String content = NetUtils.getContent(new URL(getServiceMap().get(SettingsInterface.class).getServiceRepositoryUrl() + "/modelcheckers"), 5000);
JSONObject root = new JSONObject(new JSONTokener(content));
JSONArray modelCheckersJson = root.getJSONArray("modelcheckers");
for (int i = 0; i < modelCheckersJson.length(); i++) {
JSONObject modelCheckerJson = modelCheckersJson.getJSONObject(i);
SModelCheckerInstance sModelChecker = new SModelCheckerInstance();
sModelChecker.setName(modelCheckerJson.getString("name"));
sModelChecker.setCode(modelCheckerJson.getString("code"));
sModelChecker.setDescription(modelCheckerJson.getString("description"));
sModelChecker.setModelCheckerPluginClassName(modelCheckerJson.getString("modelCheckerPluginClassName"));
modelCheckers.add(sModelChecker);
}
return modelCheckers;
} catch (Exception e) {
return handleException(e);
}
}
示例6: jsonFromElement
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
private JSONObject jsonFromElement(final AtlasElement element) throws JSONException {
final ObjectNode objectNode = this.objectNodeFromElement(element);
try {
return new JSONObject(new JSONTokener(MAPPER.writeValueAsString(objectNode)));
} catch (IOException ioe) {
// repackage this as a JSONException...seems sensible as the caller will only know about
// the jettison object not being created
throw new JSONException(ioe);
}
}
示例7: createXMLStreamReader
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
public XMLStreamReader createXMLStreamReader(JSONTokener tokener) throws XMLStreamException {
try {
JSONObject root = createJSONObject(tokener);
return new MappedXMLStreamReader(root, convention);
} catch (JSONException e) {
int column = e.getColumn();
if (column == -1) {
throw new XMLStreamException(e);
} else {
throw new XMLStreamException(e.getMessage(),
new ErrorLocation(e.getLine(), e.getColumn()),
e);
}
}
}
示例8: createXMLStreamReader
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
public XMLStreamReader createXMLStreamReader(JSONTokener tokener) throws XMLStreamException {
try {
JSONObject root = new JSONObject(tokener);
return new BadgerFishXMLStreamReader(root);
} catch (JSONException e) {
throw new XMLStreamException(e);
}
}
示例9: createXMLStreamReader
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
public XMLStreamReader createXMLStreamReader(Reader reader) throws XMLStreamException {
try {
return createXMLStreamReader(new JSONTokener(readAll(reader)));
} catch (IOException e) {
throw new XMLStreamException(e);
}
}
示例10: doTestEvents
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
private void doTestEvents(String json, String expXml) throws JSONException, XMLStreamException,
FactoryConfigurationError {
JSONObject obj = new JSONObject(new JSONTokener(json));
Configuration config = new Configuration();
ArrayList refEvents = new ArrayList();
// reference reader
XMLStreamReader refReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(expXml));
while (refReader.hasNext()) {
refEvents.add(Integer.valueOf(refReader.next()));
}
refReader.close();
// tested reader
MappedXMLStreamReader mpdReader = new MappedXMLStreamReader(obj, new MappedNamespaceConvention(config));
ArrayList mpdEvents = new ArrayList();
StringBuilder sb = new StringBuilder();
while (mpdReader.hasNext()) {
int eventType = mpdReader.next();
mpdEvents.add(Integer.valueOf(eventType));
if (eventType == XMLStreamConstants.START_ELEMENT) {
sb.append("<").append(mpdReader.getName()).append(">");
} else if (eventType == XMLStreamConstants.CHARACTERS) {
sb.append(mpdReader.getTextCharacters());
} else if (eventType == XMLStreamConstants.END_ELEMENT) {
sb.append("</").append(mpdReader.getName()).append(">");
}
}
mpdReader.close();
String mpdXml = sb.toString();
assertEquals(expXml, mpdXml);
assertEquals(refEvents, mpdEvents);
}
示例11: getReader
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
/**
* Gives the StAX reader using the "Badgerfish" formatted input JSON String.
*
* @return The XMLStreamReader according to the JSON String.
* @throws javax.xml.stream.XMLStreamException
* if there is an error while making the StAX reader.
*/
@Override
public javax.xml.stream.XMLStreamReader getReader() throws javax.xml.stream.XMLStreamException {
//input factory for "Badgerfish"
BadgerFishXMLInputFactory inputFactory = new BadgerFishXMLInputFactory();
return inputFactory.createXMLStreamReader(
new JSONTokener("{" + localName + ":" + this.getJSONString()));
}
示例12: getReader
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
/**
* Gives the StAX reader using the "Mapped" formatted input JSON String.
*
* @return The XMLStreamReader according to the JSON String.
* @throws javax.xml.stream.XMLStreamException
* if there is an error while making the StAX reader.
*/
@Override
public XMLStreamReader getReader() throws XMLStreamException {
HashMap XMLToJSNNamespaceMap = new HashMap();
XMLToJSNNamespaceMap.put("", "");
//input factory for "Mapped" convention
MappedXMLInputFactory inputFactory = new MappedXMLInputFactory(XMLToJSNNamespaceMap);
String jsonString = "{" + localName + ":" + this.getJSONString();
return inputFactory.createXMLStreamReader(new JSONTokener(jsonString));
}
示例13: getAllServiceDescriptors
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
@Override
public List<SServiceDescriptor> getAllServiceDescriptors() throws ServerException, UserException {
requireRealUserAuthentication();
try {
List<SServiceDescriptor> sServiceDescriptors = new ArrayList<SServiceDescriptor>();
URL url = new URL(getServiceMap().get(SettingsInterface.class).getServiceRepositoryUrl() + "/services.json");
String content = NetUtils.getContent(url, 5000);
JSONObject root = new JSONObject(new JSONTokener(content));
JSONArray services = root.getJSONArray("services");
for (int i = 0; i < services.length(); i++) {
JSONObject service = services.getJSONObject(i);
SServiceDescriptor sServiceDescriptor = new SServiceDescriptor();
sServiceDescriptor.setName(service.getString("name"));
sServiceDescriptor.setIdentifier(service.getString("identifier"));
sServiceDescriptor.setDescription(service.getString("description"));
sServiceDescriptor.setNotificationProtocol(SAccessMethod.valueOf(service.getString("notificationProtocol")));
sServiceDescriptor.setTrigger(STrigger.valueOf(service.getString("trigger")));
sServiceDescriptor.setUrl(service.getString("url"));
sServiceDescriptor.setCompanyUrl(service.getString("companyUrl"));
sServiceDescriptor.setTokenUrl(service.getString("tokenUrl"));
sServiceDescriptor.setNewProfileUrl(service.getString("newProfileUrl"));
sServiceDescriptor.setProviderName(service.getString("providerName"));
sServiceDescriptor.setRegisterUrl(service.getString("registerUrl"));
sServiceDescriptor.setAuthorizeUrl(service.getString("authorizeUrl"));
JSONObject rights = service.getJSONObject("rights");
sServiceDescriptor.setReadRevision(rights.has("readRevision") && rights.getBoolean("readRevision"));
sServiceDescriptor.setReadExtendedData(rights.has("readExtendedData") ? rights.getString("readExtendedData") : null);
sServiceDescriptor.setWriteRevision(rights.has("writeRevision") && rights.getBoolean("writeRevision"));
sServiceDescriptor.setWriteExtendedData(rights.has("writeExtendedData") ? rights.getString("writeExtendedData") : null);
sServiceDescriptors.add(sServiceDescriptor);
}
sort(sServiceDescriptors);
return sServiceDescriptors;
} catch (Exception e) {
return handleException(e);
}
}
示例14: getExtendedDataSchemaFromRepository
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
@Override
public SExtendedDataSchema getExtendedDataSchemaFromRepository(String namespace) throws UserException, ServerException {
requireRealUserAuthentication();
try {
String content = NetUtils.getContent(new URL(getServiceMap().get(SettingsInterface.class).getServiceRepositoryUrl() + "/extendeddataschemas?namespace=" + namespace), 5000);
JSONObject root = new JSONObject(new JSONTokener(content));
SExtendedDataSchema sExtendedDataSchema = new SExtendedDataSchema();
sExtendedDataSchema.setName(root.getString("name"));
sExtendedDataSchema.setContentType(root.getString("contentType"));
sExtendedDataSchema.setUrl(root.getString("url"));
return sExtendedDataSchema;
} catch (Exception e) {
return handleException(e);
}
}
示例15: createJSONObject
import org.codehaus.jettison.json.JSONTokener; //导入依赖的package包/类
protected JSONObject createJSONObject(JSONTokener tokener) throws JSONException {
return new JSONObject(tokener);
}