leap.lang.json.JSON.parse()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中leap.lang.json.JSON.parse()方法的一些代码示例,展示了JSON.parse()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.parse()方法的具体详情如下:
包路径:leap.lang.json.JSON
类名称:JSON
方法名:parse

JSON.parse介绍

[英]Parse the json string and returns the result as JsonValue.
[中]解析json字符串并将结果作为JsonValue返回。

代码示例

代码示例来源:origin: org.leapframework/jmms-engine

public Object parse(String s) {
  return JSON.parse(s);
}

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the json string and returns the the array.
 */
public static Object[] decodeArray(String json){
  return parse(json).asArray();
}

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the json.
 */
default void parseJson(String json) {
  parseJson(JSON.parse(json));
}

代码示例来源:origin: org.leapframework/leap-webunit

/**
 * Returns the content of response body as {@link JsonValue}.
 */
default JsonValue getJson() {
  return JSON.parse(getContent());
}

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the json string and returns the the array.
 */
public static Map<String,Object> decodeMap(String json){
  return parse(json).asMap();
}

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the json string and returns the the array.
 */
public static Object[] decodeArray(Reader json){
  return parse(json).asArray();
}

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the json string and returns the the array of the given type.
 */
public static <T> T[] decodeArray(Reader json, Class<T> componentType){
  T[] a = (T[])Array.newInstance(componentType, 0);
  return (T[])Converts.convert(parse(json).asArray(), a.getClass(), null, convertContext);
}

代码示例来源:origin: org.leapframework/leap-lang

/**
 * Parse the json string and returns the the array of the given type.
 */
public static <T> T[] decodeArray(String json, Class<T> componentType){
  T[] a = (T[])Array.newInstance(componentType, 0);
  return (T[])Converts.convert(parse(json).asArray(), a.getClass(), null, convertContext);
}

代码示例来源:origin: org.leapframework/jmms-engine

protected void setSwagger(ApiImpl api) {
  Try.throwUnchecked(() -> {
    StringBuilder s = new StringBuilder();
    swaggerJsonWriter.write(api.getMetadata(), s);
    JsonObject swagger = JSON.parse(s.toString()).asJsonObject();
    api.setSwagger(swagger);
  });
}

代码示例来源:origin: org.leapframework/leap-spring-boot-web

@Override
public Object read(Type type, Class contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
  if(type instanceof Class<?>) {
    return readInternal((Class)type, inputMessage);
  }else {
    ParameterizedType parameterizedType = (ParameterizedType)type;
    Class typeArgument = (Class)parameterizedType.getActualTypeArguments()[0];
    Collection c = newCollection((Class)parameterizedType.getRawType());
    try(InputStream is = inputMessage.getBody()) {
      try(InputStreamReader reader = new InputStreamReader(is, getCharset(inputMessage))) {
        try {
          JsonArray a = JSON.parse(reader).asJsonArray();
          a.forEach(item -> {
            if(null == item) {
              c.add(null);
            }else {
              Object o = Reflection.newInstance(typeArgument);
              ((JsonParsable)o).parseJson(item);
              c.add(o);
            }
          });
        }catch (Exception e) {
          throw new HttpMessageNotReadableException(e.getMessage(), e);
        }
      }
    }
    return c;
  }
}

代码示例来源:origin: org.leapframework/leap-spring-boot-web

@Override
protected Object readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
  try(InputStream is = inputMessage.getBody()) {
    if(clazz.isArray()) {
      try(InputStreamReader reader = new InputStreamReader(is, getCharset(inputMessage))) {
        try {
          JsonArray a = JSON.parse(reader).asJsonArray();
          Object o = Array.newInstance(clazz.getComponentType(), a.length());
          for(int i=0;i<a.length();i++) {
            Object item = Reflection.newInstance(clazz.getComponentType());
            ((JsonParsable)item).parseJson(a.getObject(i));
            Array.set(o, i, item);
          }
          return o;
        }catch (Exception e) {
          throw new HttpMessageNotReadableException(e.getMessage(), e);
        }
      }
    }else {
      Object o = Reflection.newInstance(clazz);
      try {
        ((JsonParsable)o).parseJson(IO.readString(is, getCharset(inputMessage)));
        return o;
      }catch (Exception e) {
        throw new HttpMessageNotReadableException(e.getMessage(), e);
      }
    }
  }
}

代码示例来源:origin: org.leapframework/leap-core

protected Map<String, Object> verify(String content, String payload, String signature) {
  if (!verifySignature(content, signature)) {
    throw new TokenVerifyException(ErrorCode.INVALID_SIGNATURE, "Signature verification failed");
  }
  JsonValue json;
  try {
    json = JSON.parse(JWT.base64UrlDeocodeToString(payload));
  } catch (Exception e) {
    throw new TokenVerifyException(ErrorCode.INVALID_PAYLOAD, "Parse payload as json object failed, " + e.getMessage());
  }
  if (!json.isMap()) {
    throw new TokenVerifyException(ErrorCode.INVALID_PAYLOAD, "The payload must be json object '{..}'");
  }
  //get claims
  Map<String, Object> claims = json.asMap();
  //verify expiration
  verifyExpiration(claims);
  return claims;
}

代码示例来源:origin: org.leapframework/jmms-engine

public MetaModel read(Resource file) {
  String content = file.getContent().trim();
  if (content.length() == 0) {
    return null;
  }
  String name = Strings.upperFirst(Paths.getFileNameWithoutExtension(file.getFilename()));
  JsonObject o = JSON.parse(file.getContent()).asJsonObject();
  if(o.asMap().isEmpty()) {
    return null;
  }
  MetaModel model = JSON.convert(o.asMap(), MetaModel.class);
  if (!Strings.isEmpty(model.getClassName())) {
    Class<?> c = Classes.tryForName(model.getClassName());
    if (null == c) {
      throw new IllegalStateException("Model class '" + model.getClassName() + "' not found!");
    }
    MType type = MTypes.getMType(c);
    if (!type.isComplexType()) {
      throw new IllegalStateException("The model class '" + model.getClassName() + "' must be complex type!");
    }
    MetaUtils.tryCopyModel(type.asComplexType(), model);
  }
  MApiModelBuilder am = nonValidateSwaggerReader.readModel(name, o.asMap(), new SwaggerTypeEx());
  MetaUtils.tryCopyModel(am, model);
  validator.validate("Model(" + model.getName() + ")", model);
  return model;
}

代码示例来源:origin: org.leapframework/leap-oauth2-webapp

protected AccessToken fetchAccessToken(HttpRequest request) {
  if(null != config.getClientId()){
    request.addHeader(Headers.AUTHORIZATION, "Basic " +
        Base64.encode(config.getClientId()+":"+config.getClientSecret()));
  }
  HttpResponse response = request.send();
  if(ContentTypes.APPLICATION_JSON_TYPE.isCompatible(response.getContentType())){
    String content = response.getString();
    log.debug("Received response : {}", content);
    JsonValue json = JSON.parse(content);
    if(!json.isMap()) {
      throw new OAuth2InternalServerException("Invalid response from auth server : not a json map");
    }else{
      Map<String, Object> map = json.asMap();
      String error = (String)map.get("error");
      if(Strings.isEmpty(error)) {
        return createAccessToken(map);
      }else{
        throw new OAuth2InternalServerException("Auth server response error '" + error + "' : " + map.get("error_description"));
      }
    }
  }else{
    throw new OAuth2InternalServerException("Invalid response from auth server");
  }
}

代码示例来源:origin: org.leapframework/leap-oauth2-webapp

JsonValue json = JSON.parse(content);

代码示例来源:origin: org.leapframework/leap-oauth2

JsonValue json = JSON.parse(content);

代码示例来源:origin: org.leapframework/leap-oauth2-webapp

JsonValue json = JSON.parse(content);

相关文章