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


Java JSON类代码示例

本文整理汇总了Java中org.mortbay.util.ajax.JSON的典型用法代码示例。如果您正苦于以下问题:Java JSON类的具体用法?Java JSON怎么用?Java JSON使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testWriteJson

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testWriteJson() throws Exception {
  StringWriter sw = new StringWriter();
  ConfServlet.writeResponse(getTestConf(), sw, "json");
  String json = sw.toString();
  boolean foundSetting = false;
  Object parsed = JSON.parse(json);
  Object[] properties = ((Map<String, Object[]>)parsed).get("properties");
  for (Object o : properties) {
    Map<String, Object> propertyInfo = (Map<String, Object>)o;
    String key = (String)propertyInfo.get("key");
    String val = (String)propertyInfo.get("value");
    String resource = (String)propertyInfo.get("resource");
    System.err.println("k: " + key + " v: " + val + " r: " + resource);
    if (TEST_KEY.equals(key) && TEST_VAL.equals(val)
        && "programmatically".equals(resource)) {
      foundSetting = true;
    }
  }
  assertTrue(foundSetting);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:TestConfServlet.java

示例2: getDeadNodes

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
/**
 * Returned information is a JSON representation of map with host name as the
 * key and value is a map of dead node attribute keys to its values
 */
@Override // NameNodeMXBean
public String getDeadNodes() {
  final Map<String, Map<String, Object>> info = 
    new HashMap<String, Map<String, Object>>();
  final List<DatanodeDescriptor> dead = new ArrayList<DatanodeDescriptor>();
  blockManager.getDatanodeManager().fetchDatanodes(null, dead, true);
  for (DatanodeDescriptor node : dead) {
    Map<String, Object> innerinfo = ImmutableMap.<String, Object>builder()
        .put("lastContact", getLastContact(node))
        .put("decommissioned", node.isDecommissioned())
        .put("xferaddr", node.getXferAddr())
        .build();
    info.put(node.getHostName() + ":" + node.getXferPort(), innerinfo);
  }
  return JSON.toString(info);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:FSNamesystem.java

示例3: getDecomNodes

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
/**
 * Returned information is a JSON representation of map with host name as the
 * key and value is a map of decommissioning node attribute keys to its
 * values
 */
@Override // NameNodeMXBean
public String getDecomNodes() {
  final Map<String, Map<String, Object>> info = 
    new HashMap<String, Map<String, Object>>();
  final List<DatanodeDescriptor> decomNodeList = blockManager.getDatanodeManager(
      ).getDecommissioningNodes();
  for (DatanodeDescriptor node : decomNodeList) {
    Map<String, Object> innerinfo = ImmutableMap
        .<String, Object> builder()
        .put("xferaddr", node.getXferAddr())
        .put("underReplicatedBlocks",
            node.decommissioningStatus.getUnderReplicatedBlocks())
        .put("decommissionOnlyReplicas",
            node.decommissioningStatus.getDecommissionOnlyReplicas())
        .put("underReplicateInOpenFiles",
            node.decommissioningStatus.getUnderReplicatedInOpenFiles())
        .build();
    info.put(node.getHostName() + ":" + node.getXferPort(), innerinfo);
  }
  return JSON.toString(info);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:FSNamesystem.java

示例4: getCorruptFiles

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
@Override  // NameNodeMXBean
public String getCorruptFiles() {
  List<String> list = new ArrayList<String>();
  Collection<FSNamesystem.CorruptFileBlockInfo> corruptFileBlocks;
  try {
    corruptFileBlocks = listCorruptFileBlocks("/", null);
    int corruptFileCount = corruptFileBlocks.size();
    if (corruptFileCount != 0) {
      for (FSNamesystem.CorruptFileBlockInfo c : corruptFileBlocks) {
        list.add(c.toString());
      }
    }
  } catch (IOException e) {
    LOG.warn("Get corrupt file blocks returned error: " + e.getMessage());
  }
  return JSON.toString(list);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:FSNamesystem.java

示例5: testWriteJson

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testWriteJson() throws Exception {
  StringWriter sw = new StringWriter();
  ConfServlet.writeResponse(getTestConf(), sw, "json");
  String json = sw.toString();
  boolean foundSetting = false;
  Object parsed = JSON.parse(json);
  Object[] properties = ((Map<String, Object[]>)parsed).get("properties");
  for (Object o : properties) {
    Map<String, Object> propertyInfo = (Map<String, Object>)o;
    String key = (String)propertyInfo.get("key");
    String val = (String)propertyInfo.get("value");
    String resource = (String)propertyInfo.get("resource");
    System.err.println("k: " + key + " v: " + val + " r: " + resource);
    if (TEST_KEY.equals(key) && TEST_VAL.equals(val)
        && "programatically".equals(resource)) {
      foundSetting = true;
    }
  }
  assertTrue(foundSetting);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:TestConfServlet.java

示例6: testCrossPlatform

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
public void testCrossPlatform() {
    File pubFile = new File("pub.base64cert");
    File priFile = new File("pri.base64cert");
    File testFile = new File("java.json");
    String pubKey = readFile(pubFile);
    String priKey = readFile(priFile);
    String dataStr = readFile(testFile);
    Map<String, String> data = (Map) JSON.parse(dataStr);

    XRsa rsa = new XRsa(pubKey, priKey);
    String decrypted = rsa.privateDecrypt(data.get("encrypted"));
    assertEquals(data.get("data"), decrypted);

    String sign = rsa.sign(data.get("data"));
    Boolean isValid = rsa.verify(data.get("data"), sign);
    assertTrue(isValid);
}
 
开发者ID:liamylian,项目名称:x-rsa,代码行数:18,代码来源:XRsaTest.java

示例7: getDeadNodes

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
/**
 * Returned information is a JSON representation of map with host name as the
 * key and value is a map of dead node attribute keys to its values
 */
@Override // NameNodeMXBean
public String getDeadNodes() {
  final Map<String, Map<String, Object>> info = 
    new HashMap<String, Map<String, Object>>();
  final List<DatanodeDescriptor> dead = new ArrayList<DatanodeDescriptor>();
  blockManager.getDatanodeManager().fetchDatanodes(null, dead, false);
  for (DatanodeDescriptor node : dead) {
    Map<String, Object> innerinfo = ImmutableMap.<String, Object>builder()
        .put("lastContact", getLastContact(node))
        .put("decommissioned", node.isDecommissioned())
        .put("xferaddr", node.getXferAddr())
        .build();
    info.put(node.getHostName() + ":" + node.getXferPort(), innerinfo);
  }
  return JSON.toString(info);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:21,代码来源:FSNamesystem.java

示例8: parse

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
public Message[] parse(Reader reader) throws IOException
{
    JSON.ReaderSource source =_readerPool.poll();
    if (source==null)
        source=new JSON.ReaderSource(reader);
    else
        source.setReader(reader);
    
    Object batch=_batchJSON.parse(source);
    _readerPool.offer(source);

    if (batch==null)
        return new Message[0]; 
    if (batch.getClass().isArray())
        return (Message[])batch;
    return new Message[]{(Message)batch};
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:18,代码来源:MessagePool.java

示例9: filter

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
public Object filter(Client from, Channel to, Object data) throws IllegalStateException
{
    if (data==null)
        return null;
    
    if (data instanceof Map)
        return filterMap(from,to,(Map)data);
    if (data instanceof List)
        return filterArray(from,to,((List) data).toArray ());
    if (data instanceof Collection)
    	return filterArray(from,to,((Collection)data).toArray());
    if (data.getClass().isArray() )
        return filterArray(from,to,data);
    if (data instanceof Number)
        return filterNumber((Number)data);
    if (data instanceof Boolean)
        return filterBoolean((Boolean)data);
    if (data instanceof String)
        return filterString((String)data);
    if (data instanceof JSON.Literal)
        return filterJSON(from,to,(JSON.Literal)data);
    if (data instanceof JSON.Generator)
        return filterJSON(from,to,(JSON.Generator)data);
    return filterObject(from,to,data);
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:26,代码来源:JSONDataFilter.java

示例10: setMessages

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
protected void setMessages(Queue<Message> messages)
{
    try
    {
        for (Message msg : messages)
        {
            msg.put(Bayeux.CLIENT_FIELD,_clientId);
        }
        String json=JSON.toString(messages);

        if (_formEncoded)
            setRequestContent(new ByteArrayBuffer("message="+URLEncoder.encode(json,"utf-8")));
        else
            setRequestContent(new ByteArrayBuffer(json,"utf-8"));

    }
    catch (Exception e)
    {
        Log.warn(e);
    }

}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:23,代码来源:BayeuxClient.java

示例11: toJsonString

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
/** Convert a AclStatus object to a Json string. */
public static String toJsonString(final AclStatus status) {
  if (status == null) {
    return null;
  }

  final Map<String, Object> m = new TreeMap<String, Object>();
  m.put("owner", status.getOwner());
  m.put("group", status.getGroup());
  m.put("stickyBit", status.isStickyBit());
  m.put("entries", status.getEntries());
  final Map<String, Map<String, Object>> finalMap =
      new TreeMap<String, Map<String, Object>>();
  finalMap.put(AclStatus.class.getSimpleName(), m);
  return JSON.toString(finalMap);
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:17,代码来源:JsonUtil.java

示例12: toXAttrNames

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
public static List<String> toXAttrNames(final Map<?, ?> json)
    throws IOException {
  if (json == null) {
    return null;
  }

  final String namesInJson = (String) json.get("XAttrNames");
  final Object[] xattrs = (Object[]) JSON.parse(namesInJson);
  final List<String> names = Lists.newArrayListWithCapacity(json.keySet()
      .size());

  for (int i = 0; i < xattrs.length; i++) {
    names.add((String) (xattrs[i]));
  }
  return names;
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:17,代码来源:JsonUtil.java

示例13: getState

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
/**
 * Method invoked by a JMX client to get the state of the CertificateLocalization service.
 * Under the attributes tab.
 * @return It returns a map with the name of the material and the number of references.
 */
@Override
public String getState() {
  ImmutableMap<StorageKey, CryptoMaterial> state;
  try {
    lock.lock();
    state = ImmutableMap.copyOf(materialLocation);
  } finally {
    lock.unlock();
  }
  
  ReturnState<String, String> returnState = new ReturnState<>();
  
  ReturnState<String, Integer> internalState = new ReturnState<>();
  for (Map.Entry<StorageKey, CryptoMaterial> entry : state.entrySet()) {
    internalState.put(entry.getKey().getUsername(), entry.getValue().getRequestedApplications());
  }
  returnState.put(JMX_MATERIALIZED_KEY, JSON.toString(internalState));
  
  return JSON.toString(returnState);
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:26,代码来源:CertificateLocalizationService.java

示例14: testHdfsFileStatus

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
@Test
public void testHdfsFileStatus() {
  final long now = Time.now();
  final String parent = "/dir";
  final HdfsFileStatus status = new HdfsFileStatus(1001L, false, 3, 1L << 26,
      now, now + 10, new FsPermission((short) 0644), "user", "group",
      DFSUtil.string2Bytes("bar"), DFSUtil.string2Bytes("foo"),
      INodeId.GRANDFATHER_INODE_ID, 0, null, (byte) 0);
  final FileStatus fstatus = toFileStatus(status, parent);
  System.out.println("status  = " + status);
  System.out.println("fstatus = " + fstatus);
  final String json = JsonUtil.toJsonString(status, true);
  System.out.println("json    = " + json.replace(",", ",\n  "));
  final HdfsFileStatus s2 = JsonUtil.toFileStatus((Map<?, ?>)JSON.parse(json), true);
  final FileStatus fs2 = toFileStatus(s2, parent);
  System.out.println("s2      = " + s2);
  System.out.println("fs2     = " + fs2);
  Assert.assertEquals(fstatus, fs2);
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:20,代码来源:TestJsonUtil.java

示例15: testToAclStatus

import org.mortbay.util.ajax.JSON; //导入依赖的package包/类
@Test
public void testToAclStatus() {
  String jsonString =
      "{\"AclStatus\":{\"entries\":[\"user::rwx\",\"user:user1:rw-\",\"group::rw-\",\"other::r-x\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
  Map<?, ?> json = (Map<?, ?>) JSON.parse(jsonString);

  List<AclEntry> aclSpec =
      Lists.newArrayList(aclEntry(ACCESS, USER, ALL),
          aclEntry(ACCESS, USER, "user1", READ_WRITE),
          aclEntry(ACCESS, GROUP, READ_WRITE),
          aclEntry(ACCESS, OTHER, READ_EXECUTE));

  AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
  aclStatusBuilder.owner("testuser");
  aclStatusBuilder.group("supergroup");
  aclStatusBuilder.addEntries(aclSpec);
  aclStatusBuilder.stickyBit(false);

  Assert.assertEquals("Should be equal", aclStatusBuilder.build(),
      JsonUtil.toAclStatus(json));
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:22,代码来源:TestJsonUtil.java


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