本文整理了Java中org.eclipse.jetty.util.ajax.JSON
类的一些代码示例,展示了JSON
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON
类的具体详情如下:
包路径:org.eclipse.jetty.util.ajax.JSON
类名称:JSON
[英]JSON Parser and Generator.
This class provides some static methods to convert POJOs to and from JSON notation. The mapping from JSON to java is:
object ==> Map
array ==> Object[]
number ==> Double or Long
string ==> String
null ==> null
bool ==> Boolean
The java to JSON mapping is:
String --> string
Number --> number
Map --> object
List --> array
Array --> array
null --> null
Boolean--> boolean
Object --> string (dubious!)
The interface JSON.Convertible may be implemented by classes that wish to externalize and initialize specific fields to and from JSON objects. Only directed acyclic graphs of objects are supported.
The interface JSON.Generator may be implemented by classes that know how to render themselves as JSON and the #toString(Object) method will use JSON.Generator#addJSON(Appendable) to generate the JSON. The class JSON.Literal may be used to hold pre-generated JSON object.
The interface JSON.Convertor may be implemented to provide static converters for objects that may be registered with #registerConvertor(Class,Convertor). These converters are looked up by class, interface and super class by #getConvertor(Class).
If a JSON object has a "class" field, then a java class for that name is loaded and the method #convertTo(Class,Map) is used to find a JSON.Convertor for that class.
If a JSON object has a "x-class" field then a direct lookup for a JSON.Convertor for that class name is done (without loading the class).
[中]JSON解析器和生成器。
此类提供了一些静态方法来将POJO转换为JSON表示法和从JSON表示法转换为POJO。从JSON到java的映射是:
object ==> Map
array ==> Object[]
number ==> Double or Long
string ==> String
null ==> null
bool ==> Boolean
java到JSON的映射是:
String --> string
Number --> number
Map --> object
List --> array
Array --> array
null --> null
Boolean--> boolean
Object --> string (dubious!)
接口JSON。可转换可以由希望外部化和初始化JSON对象之间的特定字段的类实现。仅支持对象的有向无环图。
接口是JSON。生成器可以由知道如何将自己呈现为JSON的类实现,而#toString(Object)方法将使用JSON。生成器#addJSON(可追加)生成JSON。类JSON。Literal可用于保存预生成的JSON对象。
接口是JSON。转换器可以被实现为向#registerConvertor(类,转换器)注册的对象提供静态转换器。通过#getConvertor(class)按类、接口和超类查找这些转换器。
如果一个JSON对象有一个“class”字段,则加载该名称的java类,并使用方法#convertTo(class,Map)查找JSON。该类的转换器。
如果JSON对象有一个“x-class”字段,则直接查找JSON。完成该类名的转换器(不加载该类)。
代码示例来源:origin: apache/hbase
@GET
@Path("{" + PATH + ":.*}")
@Produces({MediaType.APPLICATION_JSON})
public Response get(
@PathParam(PATH) @DefaultValue("UNKNOWN_" + PATH) final String path,
@QueryParam(OP) @DefaultValue("UNKNOWN_" + OP) final String op
) throws IOException {
LOG.info("get: " + PATH + "=" + path + ", " + OP + "=" + op);
final Map<String, Object> m = new TreeMap<>();
m.put(PATH, path);
m.put(OP, op);
final String js = JSON.toString(m);
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
}
}
代码示例来源:origin: apache/hbase
@SuppressWarnings("unchecked")
private static Map<String, Object> parse(String jsonString) {
return (Map<String, Object>)JSON.parse(jsonString);
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
appendMap(buffer,(Map)object);
appendString(buffer,(String)object);
appendNumber(buffer,(Number)object);
appendBoolean(buffer,(Boolean)object);
appendArray(buffer,object);
appendString(buffer,object.toString());
appendJSON(buffer,(Convertible)object);
appendJSON(buffer,(Generator)object);
Convertor convertor = getConvertor(object.getClass());
if (convertor != null)
appendJSON(buffer,convertor,object);
appendArray(buffer,(Collection)object);
appendString(buffer,object.toString());
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public void appendArray(Appendable buffer, Object array)
{
try
{
if (array == null)
{
appendNull(buffer);
return;
}
buffer.append('[');
int length = Array.getLength(array);
for (int i = 0; i < length; i++)
{
if (i != 0)
buffer.append(',');
append(buffer,Array.get(array,i));
}
buffer.append(']');
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public void toJSON(Object obj, Output out)
{
String clsName=obj.getClass().getName();
Convertor convertor=_json.getConvertorFor(clsName);
if (convertor==null)
{
try
{
Class cls=Loader.loadClass(JSON.class,clsName);
convertor=new JSONPojoConvertor(cls,_fromJson);
_json.addConvertorFor(clsName, convertor);
}
catch (ClassNotFoundException e)
{
JSON.LOG.warn(e);
}
}
if (convertor!=null)
{
convertor.toJSON(obj, out);
}
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp
public void appendMap(Appendable buffer, Map<?,?> map)
{
try
{
if (map == null)
{
appendNull(buffer);
return;
}
buffer.append('{');
Iterator<?> iter = map.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry<?,?> entry = (Map.Entry<?,?>)iter.next();
QuotedStringTokenizer.quote(buffer,entry.getKey().toString());
buffer.append(':');
append(buffer,entry.getValue());
if (iter.hasNext())
buffer.append(',');
}
buffer.append('}');
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public static String toString(Map object)
{
StringBuilder buffer = new StringBuilder(DEFAULT.getStringBufferSize());
DEFAULT.appendMap(buffer,object);
return buffer.toString();
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp
public static String toString(Object[] array)
{
StringBuilder buffer = new StringBuilder(DEFAULT.getStringBufferSize());
DEFAULT.appendArray(buffer,array);
return buffer.toString();
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public void appendBoolean(Appendable buffer, Boolean b)
{
try
{
if (b == null)
{
appendNull(buffer);
return;
}
buffer.append(b?"true":"false");
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.eclipse.jetty/jetty-util-ajax
public void appendMap(Appendable buffer, Map<?,?> map)
{
try
{
if (map == null)
{
appendNull(buffer);
return;
}
buffer.append('{');
Iterator<?> iter = map.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry<?,?> entry = (Map.Entry<?,?>)iter.next();
quotedEscape(buffer, entry.getKey().toString());
buffer.append(':');
append(buffer,entry.getValue());
if (iter.hasNext())
buffer.append(',');
}
buffer.append('}');
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public void appendJSON(final Appendable buffer, final Convertor convertor, final Object object)
{
appendJSON(buffer,new Convertible()
{
public void fromJSON(Map object)
{
}
public void toJSON(Output out)
{
convertor.toJSON(object,out);
}
});
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public static String toString(Object object)
{
StringBuilder buffer = new StringBuilder(DEFAULT.getStringBufferSize());
DEFAULT.append(buffer,object);
return buffer.toString();
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
public void add(Object obj)
{
if (c == 0)
throw new IllegalStateException();
append(_buffer,obj);
c = 0;
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp
/**
* Register a {@link Convertor} for a class or interface.
*
* @param forClass
* The class or interface that the convertor applies to
* @param convertor
* the convertor
*/
public static void registerConvertor(Class forClass, Convertor convertor)
{
DEFAULT.addConvertor(forClass,convertor);
}
代码示例来源:origin: org.eclipse.jetty/jetty-util-ajax
@Override
public void add(String name, boolean value)
{
try
{
if (c == 0)
throw new IllegalStateException();
_buffer.append(c);
quotedEscape(_buffer,name);
_buffer.append(':');
appendBoolean(_buffer,value?Boolean.TRUE:Boolean.FALSE);
c = ',';
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-azure
/**
* Creates a JSON serializer that can serialize a PermissionStatus object into
* the JSON string we want in the blob metadata.
*
* @return The JSON serializer.
*/
private static JSON createPermissionJsonSerializer() {
JSON serializer = new JSON();
serializer.addConvertor(PermissionStatus.class,
new PermissionStatusJsonSerializer());
return serializer;
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp
appendMap(buffer,(Map)object);
appendString(buffer,(String)object);
appendNumber(buffer,(Number)object);
appendBoolean(buffer,(Boolean)object);
appendArray(buffer,object);
appendString(buffer,object.toString());
appendJSON(buffer,(Convertible)object);
appendJSON(buffer,(Generator)object);
Convertor convertor = getConvertor(object.getClass());
if (convertor != null)
appendJSON(buffer,convertor,object);
appendArray(buffer,(Collection)object);
appendString(buffer,object.toString());
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-plus
public void appendArray(Appendable buffer, Object array)
{
try
{
if (array == null)
{
appendNull(buffer);
return;
}
buffer.append('[');
int length = Array.getLength(array);
for (int i = 0; i < length; i++)
{
if (i != 0)
buffer.append(',');
append(buffer,Array.get(array,i));
}
buffer.append(']');
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp
public void toJSON(Object obj, Output out)
{
String clsName=obj.getClass().getName();
Convertor convertor=_json.getConvertorFor(clsName);
if (convertor==null)
{
try
{
Class cls=Loader.loadClass(JSON.class,clsName);
convertor=new JSONPojoConvertor(cls,_fromJson);
_json.addConvertorFor(clsName, convertor);
}
catch (ClassNotFoundException e)
{
JSON.LOG.warn(e);
}
}
if (convertor!=null)
{
convertor.toJSON(obj, out);
}
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-server
public void appendMap(Appendable buffer, Map<?,?> map)
{
try
{
if (map == null)
{
appendNull(buffer);
return;
}
buffer.append('{');
Iterator<?> iter = map.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry<?,?> entry = (Map.Entry<?,?>)iter.next();
QuotedStringTokenizer.quote(buffer,entry.getKey().toString());
buffer.append(':');
append(buffer,entry.getValue());
if (iter.hasNext())
buffer.append(',');
}
buffer.append('}');
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!