Package org.json.simple.parser

Examples of org.json.simple.parser.JSONParser


     
      @Override
      public void translate(Writer writer) throws TransformerException,
          IOException {
          try {
            JSONParser parser = new JSONParser();
          XMLOutputFactory factory = getOutputFactory();
          final XMLStreamWriter streamWriter = factory.createXMLStreamWriter(writer);
           
          parser.parse(r, new JsonToXmlContentHandler(escapeName(rootName, true), streamWriter));
           
          streamWriter.flush(); //woodstox needs a flush rather than a close
        } catch (XMLStreamException e) {
          throw new TransformerException(e);
        } catch (ParseException e) {
View Full Code Here


   * @param in
   * @return instance of : JSONObject,JSONArray,String,Boolean,Long,Double or null
   */
  public static Object parse(Reader in){
    try{
      JSONParser parser=new JSONParser();
      return parser.parse(in);
    }
    catch(Exception e){
      return null;
    }
  }
View Full Code Here

    }

    JSONUnpacker(MessagePack msgpack, Reader in) {
        super(msgpack, null);
        this.in = in;
        this.parser = new JSONParser();
    }
View Full Code Here

    Assert.assertEquals("http://www.geomajas.org/url1",
        fixSlash(feature.getAttributes().get("urlAttr").getValue().toString()));

    view.render(mav.getModel(), request, response);
    response.flushBuffer();
    Object json = new JSONParser().parse(response.getContentAsString());
    String isodate = GeoJSONUtil.DATE_FORMAT.format(c.getTime());
    Assert.assertTrue(json instanceof JSONObject);
    Assert.assertEquals("{\"type\":\"Feature\"," + "\"geometry\":{\"type\":\"MultiPolygon\","
        + "\"coordinates\":[[[[0.0,0.0],[1,0.0],[1,1],[0.0,1],[0.0,0.0]]]]}," + "\"properties\":{"
        + "\"stringAttr\":\"bean1\"," + "\"booleanAttr\":true," + "\"currencyAttr\":\"100,23\","
View Full Code Here

    request.setParameter("stringAttr_eq", "bean1");
    request.setParameter("epsg", "900913");
    ModelAndView mav = adapter.handle(request, response, restController);
    view.render(mav.getModel(), request, response);
    response.flushBuffer();
    Object json = new JSONParser().parse(response.getContentAsString());
    Assert.assertTrue(json instanceof JSONObject);
    JSONObject jsonObject = (JSONObject) json;
    JSONArray features = (JSONArray) jsonObject.get("features");
    JSONObject feature = (JSONObject) features.get(0);
    JSONObject geometry = (JSONObject) feature.get("geometry");
View Full Code Here

  private ApnsPayloadBuilder builder;
  private JSONParser parser;

  @Before
  public void setUp() {
    this.parser = new JSONParser();
    this.builder = new ApnsPayloadBuilder();
  }
View Full Code Here

      System.exit(-1);
    }
   
    // parse training data into clusters
    Map<String, Clusters> clusterMembership = new HashMap<String, Clusters>();
    JSONParser parser = new JSONParser();
    try {
      JSONObject parseObj = (JSONObject) parser.parse(new FileReader(trainingFile));
      JSONObject topicObj = (JSONObject) parseObj.get("topics");
      Set<String> topics = topicObj.keySet();
      Iterator<String> topicIt = topics.iterator();
      while (topicIt.hasNext()) { // for each topic
        String topic = topicIt.next();
View Full Code Here

  public WriteResponse execWrite(HttpRequestAttributes httpAttributes, Type requestType,
      List<RequestValue> resIds, SqlResource sqlResource, String requestBody,
      RequestLogger requestLogger) throws SqlResourceException {
    final Handler handler = new Handler(httpAttributes, requestType, resIds, sqlResource, requestLogger);
    try {
      final JSONParser parser = new JSONParser();
      parser.parse(requestBody, handler);
    } catch (final ParseException exception) {
      throw new InvalidRequestException("Error parsing request body: " + exception.toString());
    }
    final SqlResourceException handlerException = handler.getHandlerException();
    if (handlerException != null) {
View Full Code Here

    // TODO, assume the url is a file path for now.
    java.nio.file.Path configFile = Paths.get(configFileUrl);
    java.nio.file.Path preferenceFile = Paths.get(preferenceFileUrl);
    try {
      JSONParser parser = new JSONParser();
      JSONObject configJsonObject =
          (JSONObject) parser.parse(this.utils.readFile(configFile));
      JSONObject preferenceJsonObject =
          (JSONObject) parser.parse(this.utils.readFile(preferenceFile));

      String isAllowTracking = mergeBooleanSetting(
          "allow-anonymous-usage-tracking",
          configJsonObject,
          preferenceJsonObject);
View Full Code Here

    Assert.assertEquals(sampler.getRate(), (0d + 1 + 2 + 3) / 4, 0.0001);
    value[0] = 4;
    sampler.sample();
    Assert.assertEquals(sampler.getRate(), (4d + 1 + 2 + 3) / 4, 0.0001);

    JSONObject json = (JSONObject) new JSONParser().parse(sampler.toJSONString());
    Assert.assertEquals(json.size(), 2);
    Assert.assertEquals(json.get("sampler"), sampler.getRate());
    Assert.assertEquals(json.get("size"), 4L);

    StringWriter writer = new StringWriter();
    sampler.writeJSONString(writer);
    writer.close();
    json = (JSONObject) new JSONParser().parse(writer.toString());
    Assert.assertEquals(json.size(), 2);
    Assert.assertEquals(json.get("sampler"), sampler.getRate());
    Assert.assertEquals(json.get("size"), 4L);
  }
View Full Code Here

TOP

Related Classes of org.json.simple.parser.JSONParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.