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


Java JSONParser类代码示例

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


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


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