• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JSONParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: parse

import org.noggit.JSONParser; //导入依赖的package包/类
private void parse(JSONParser parser,
                   Handler handler,
                   Map<String, Object> values,
                   Stack<Set<String>> stack, // lists of values to purge
                   boolean recordStarted) throws IOException {

  int event = -1;
  for (; ; ) {
    event = parser.nextEvent();
    if(event == EOF) break;
    if (event == OBJECT_START) {
      handleObjectStart(parser, new HashSet<Node>(), handler, values, stack, recordStarted);
    } else if (event == ARRAY_START) {
      for (; ; ) {
        event = parser.nextEvent();
        if (event == ARRAY_END) break;
        if (event == OBJECT_START) {
          handleObjectStart(parser, new HashSet<Node>(), handler, values, stack, recordStarted);
        }
      }
    }
  }

}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:JsonRecordReader.java


示例2: load

import org.noggit.JSONParser; //导入依赖的package包/类
@Override
public void load(SolrQueryRequest req, 
    SolrQueryResponse rsp, 
    ContentStream stream, 
    UpdateRequestProcessor processor) throws Exception {
  
  Reader reader = null;
  try {
    reader = stream.getReader();
    if (log.isTraceEnabled()) {
      String body = IOUtils.toString(reader);
      log.trace("body", body);
      reader = new StringReader(body);
    }
  
    parser = new JSONParser(reader);
    this.processUpdate();
  }
  finally {
    IOUtils.closeQuietly(reader);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:JsonLoader.java


示例3: handleStreamingSingleDocs

import org.noggit.JSONParser; //导入依赖的package包/类
private void handleStreamingSingleDocs() throws IOException
{
  while( true ) {
    int ev = parser.nextEvent();
    if(ev == JSONParser.EOF) return;
    if(ev == JSONParser.OBJECT_START) {
      assertEvent(ev, JSONParser.OBJECT_START);
      AddUpdateCommand cmd = new AddUpdateCommand(req);
      cmd.commitWithin = commitWithin;
      cmd.overwrite = overwrite;
      cmd.solrDoc = parseDoc(ev);
      processor.processAdd(cmd);
    } else if(ev == JSONParser.ARRAY_START){
      handleAdds();
    } else{
      throw  new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unexpected event :"+ev);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:JsonLoader.java


示例4: getString

import org.noggit.JSONParser; //导入依赖的package包/类
String getString(int ev) throws IOException {
  switch (ev) {
    case JSONParser.STRING:
      return parser.getString();
    case JSONParser.BIGNUMBER:
    case JSONParser.NUMBER:
    case JSONParser.LONG:
      return parser.getNumberChars().toString();
    case JSONParser.BOOLEAN:
      return Boolean.toString(parser.getBoolean());
    case JSONParser.NULL:
      return null;
    default:
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
          "Expected primitive JSON value but got: "+JSONParser.getEventString( ev  )
              +" at ["+parser.getPosition()+"]" );
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:JsonLoader.java


示例5: parseSingleFieldValue

import org.noggit.JSONParser; //导入依赖的package包/类
private Object parseSingleFieldValue(int ev) throws IOException {
  switch (ev) {
    case JSONParser.STRING:
      return parser.getString();
    case JSONParser.LONG:
      return parser.getLong();
    case JSONParser.NUMBER:
      return parser.getDouble();
    case JSONParser.BIGNUMBER:
      return parser.getNumberChars().toString();
    case JSONParser.BOOLEAN:
      return parser.getBoolean();
    case JSONParser.NULL:
      parser.getNull();
      return null;
    case JSONParser.ARRAY_START:
      return parseArrayFieldValue(ev);
    default:
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing JSON field value. Unexpected "+JSONParser.getEventString(ev) );
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:JsonLoader.java


示例6: noggit

import org.noggit.JSONParser; //导入依赖的package包/类
@Benchmark
public void noggit(Blackhole bh) throws Exception {
	JSONParser p = new JSONParser(chars, 0, chars.length);
	p.setFlags(JSONParser.FLAGS_STRICT);
	int i = 0, e;
	while ((e = p.nextEvent()) != JSONParser.EOF)
		i += e;
	bh.consume(i);
}
 
开发者ID:httpdigest,项目名称:ftljson,代码行数:10,代码来源:B.java


示例7: getResponseMap

import org.noggit.JSONParser; //导入依赖的package包/类
public static Map getResponseMap(String path, RestTestHarness restHarness) throws Exception {
    String response = restHarness.query(path);
    try {
        return (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
    } catch (JSONParser.ParseException e) {
        log.error(response);
        return Collections.emptyMap();
    }
}
 
开发者ID:TYPO3-Solr,项目名称:solr-typo3-plugin,代码行数:10,代码来源:AccessFilterQParserPluginTest.java


示例8: processResponse

import org.noggit.JSONParser; //导入依赖的package包/类
public SearchResponse processResponse(InputStream body, String encoding) {
  try {
    return objectMapper.readValue(body, SearchResponse.class);
  } catch (IOException | JSONParser.ParseException e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
        "parsing error", e);
  }
}
 
开发者ID:lucidworks,项目名称:fusion-client-tools,代码行数:9,代码来源:JsonResponseParser.java


示例9: fromJSON

import org.noggit.JSONParser; //导入依赖的package包/类
public static Object fromJSON(byte[] utf8) {
  // convert directly from bytes to chars
  // and parse directly from that instead of going through
  // intermediate strings or readers
  CharArr chars = new CharArr();
  ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars);
  JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length());
  try {
    return ObjectBuilder.getVal(parser);
  } catch (IOException e) {
    throw new RuntimeException(e); // should never happen w/o using real IO
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:ZkStateReader.java


示例10: parseSingleFieldValue

import org.noggit.JSONParser; //导入依赖的package包/类
public static Object parseSingleFieldValue(int ev, JSONParser parser, MethodFrameWrapper runnable) throws IOException {
  switch (ev) {
    case STRING:
      return parser.getString();
    case LONG:
      return parser.getLong();
    case NUMBER:
      return parser.getDouble();
    case BIGNUMBER:
      return parser.getNumberChars().toString();
    case BOOLEAN:
      return parser.getBoolean();
    case NULL:
      parser.getNull();
      return null;
    case ARRAY_START:
      return parseArrayFieldValue(ev, parser,runnable);
    case  OBJECT_START:
      if(runnable !=null) {
        runnable.walk(OBJECT_START);
        return null;
      }
      consumeTillMatchingEnd(parser,1,0);
      return null;
    default:
      throw new RuntimeException("Error parsing JSON field value. Unexpected " + JSONParser.getEventString(ev));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:JsonRecordReader.java


示例11: parseArrayFieldValue

import org.noggit.JSONParser; //导入依赖的package包/类
public static List<Object> parseArrayFieldValue(int ev, JSONParser parser, MethodFrameWrapper runnable) throws IOException {
  assert ev == ARRAY_START;

  ArrayList lst = new ArrayList(2);
  for (; ; ) {
    ev = parser.nextEvent();
    if (ev == ARRAY_END) {
      if(lst.isEmpty()) return null;
      return lst;
    }
    Object val = parseSingleFieldValue(ev, parser, runnable);
    if(val != null) lst.add(val);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:JsonRecordReader.java


示例12: consumeTillMatchingEnd

import org.noggit.JSONParser; //导入依赖的package包/类
public static void consumeTillMatchingEnd(JSONParser parser, int obj, int arr) throws IOException {
  for (; ; ) {
    int event = parser.nextEvent();
    if (event == OBJECT_START) obj++;
    if (event == OBJECT_END) obj--;
    assert obj >= 0;
    if (event == ARRAY_START) arr++;
    if (event == ARRAY_END) arr--;
    assert arr >= 0;
    if (obj == 0 && arr == 0) break;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:JsonRecordReader.java


示例13: handleDeleteCommand

import org.noggit.JSONParser; //导入依赖的package包/类
void handleDeleteCommand() throws IOException {
  int ev = parser.nextEvent();
  switch (ev) {
    case JSONParser.ARRAY_START:
      handleDeleteArray(ev);
      break;
    case JSONParser.OBJECT_START:
      handleDeleteMap(ev);
      break;
    default:
      handleSingleDelete(ev);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:JsonLoader.java


示例14: handleSingleDelete

import org.noggit.JSONParser; //导入依赖的package包/类
void handleSingleDelete(int ev) throws IOException {
  if (ev == JSONParser.OBJECT_START) {
    handleDeleteMap(ev);
  } else {
    DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
    cmd.commitWithin = commitWithin;
    String id = getString(ev);
    cmd.setId(id);
    processor.processDelete(cmd);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:JsonLoader.java


示例15: handleAdds

import org.noggit.JSONParser; //导入依赖的package包/类
void handleAdds() throws IOException
{
  while( true ) {
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    cmd.commitWithin = commitWithin;
    cmd.overwrite = overwrite;

    int ev = parser.nextEvent();
    if (ev == JSONParser.ARRAY_END) break;

    assertEvent(ev, JSONParser.OBJECT_START);
    cmd.solrDoc = parseDoc(ev);
    processor.processAdd(cmd);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:JsonLoader.java


示例16: assertEvent

import org.noggit.JSONParser; //导入依赖的package包/类
void assertEvent(int ev, int expected) {
  if( ev != expected ) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "Expected: "+JSONParser.getEventString( expected  )
        +" but got "+JSONParser.getEventString( ev )
        +" at ["+parser.getPosition()+"]" );
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:JsonLoader.java


示例17: parseFieldValue

import org.noggit.JSONParser; //导入依赖的package包/类
private void parseFieldValue(SolrInputField sif) throws IOException {
  int ev = parser.nextEvent();
  if (ev == JSONParser.OBJECT_START) {
    parseExtendedFieldValue(sif, ev);
  } else {
    Object val = parseNormalFieldValue(ev);
    sif.setValue(val, 1.0f);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:JsonLoader.java


示例18: handleResponse

import org.noggit.JSONParser; //导入依赖的package包/类
public Map<String,Object> handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
  HttpEntity entity = response.getEntity();
  if (entity != null) {
    Object resp = ObjectBuilder.getVal(new JSONParser(EntityUtils.toString(entity)));
    if (resp != null && resp instanceof Map) {
      return (Map<String,Object>)resp;
    } else {
      throw new ClientProtocolException("Expected JSON object in response but received "+ resp);
    }
  } else {
    StatusLine statusLine = response.getStatusLine();
    throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
  }
}
 
开发者ID:lucidworks,项目名称:yarn-proto,代码行数:15,代码来源:SolrClient.java


示例19: handleAdds

import org.noggit.JSONParser; //导入依赖的package包/类
void handleAdds() throws IOException
{
  while( true ) {
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    cmd.commitWithin = commitWithin;
    cmd.overwrite = overwrite;
  
    int ev = parser.nextEvent();
    if (ev == JSONParser.ARRAY_END) break;
  
    assertEvent(ev, JSONParser.OBJECT_START);
    cmd.solrDoc = parseDoc(ev);
    processor.processAdd(cmd);
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:16,代码来源:JsonLoader.java


示例20: parseField

import org.noggit.JSONParser; //导入依赖的package包/类
private SolrInputField parseField()  throws IOException {
  int ev = parser.nextEvent();
  if (ev == JSONParser.OBJECT_END) {
    return null;
  }
  
  String fieldName = parser.getString();
  SolrInputField sif = new SolrInputField(fieldName);
  parseFieldValue(sif);
  return sif;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:12,代码来源:JsonLoader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ImmutableList类代码示例发布时间:2022-05-22
下一篇:
Java WebMenuItem类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap