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


Java JsonParser.parse方法代码示例

本文整理汇总了Java中com.google.api.client.json.JsonParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.parse方法的具体用法?Java JsonParser.parse怎么用?Java JsonParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.client.json.JsonParser的用法示例。


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

示例1: parseResponse

import com.google.api.client.json.JsonParser; //导入方法依赖的package包/类
/**
 * Parse the response from the HTTP call into an instance of the given class.
 *
 * @param response The parsed response object
 * @param c The class to instantiate and use to build the response object
 * @return The ApiResponse object
 * @throws IOException Any IO errors
 */
protected ApiResponse parseResponse(HttpResponse response, Class<?> c) throws IOException {
  ApiResponse res = null;
  InputStream in = response.getContent();

  if (in == null) {
    try {
      res = (ApiResponse)c.newInstance();
    } catch(ReflectiveOperationException e) {
      throw new RuntimeException("Cannot instantiate " + c, e);
    }
  } else {
    try {
      JsonParser jsonParser = GsonFactory.getDefaultInstance().createJsonParser(in);
      res = (ApiResponse)jsonParser.parse(c);
    } finally {
      in.close();
    }
  }

  res.setHttpRequest(response.getRequest());
  res.setHttpResponse(response);

  return res;
}
 
开发者ID:dnsimple,项目名称:dnsimple-java,代码行数:33,代码来源:HttpEndpointClient.java

示例2: performSearch

import com.google.api.client.json.JsonParser; //导入方法依赖的package包/类
private static List<Place> performSearch( String kind, String type, double lat, double lng )
    throws IOException
{
  HttpTransport httpTransport = new NetHttpTransport();
  HttpRequestFactory hrf = httpTransport.createRequestFactory();
  
  String paramsf = "%s?location=%f,%f&rankby=distance&keyword=%s&type=%s&sensor=true&key=%s";
  String params = String.format(paramsf, SearchData.BASE_URL, lat, lng, type, kind, AuthUtils.API_KEY);
  GenericUrl url = new GenericUrl(params);
  HttpRequest hreq = hrf.buildGetRequest(url);
  HttpResponse hres = hreq.execute();

  InputStream content = hres.getContent();
  JsonParser p = new JacksonFactory().createJsonParser(content);
  SearchData searchData = p.parse(SearchData.class, null);
  
  return searchData.buildPlaces();
}
 
开发者ID:coderoshi,项目名称:glass,代码行数:19,代码来源:PlaceUtils.java

示例3: populateDetails

import com.google.api.client.json.JsonParser; //导入方法依赖的package包/类
private static Place populateDetails( Place place )
      throws IOException
  {
    // grab more restaurant details
    HttpTransport httpTransport = new NetHttpTransport();
    HttpRequestFactory hrf = httpTransport.createRequestFactory();

    String paramsf = "%s?reference=%s&sensor=true&key=%s";
    String params = String.format(paramsf, DetailsData.BASE_URL, place.getReference(), AuthUtils.API_KEY);
    GenericUrl url = new GenericUrl(params);
    HttpRequest hreq = hrf.buildGetRequest(url);
    HttpResponse hres = hreq.execute();

//    ByteArrayOutputStream os = new ByteArrayOutputStream();
//    IOUtils.copy(hres.getContent(), os, false);
//    System.out.println( os.toString() );

    InputStream content2 = hres.getContent();
    JsonParser p = new JacksonFactory().createJsonParser(content2);
    DetailsData details = p.parse(DetailsData.class, null);
    details.populatePlace( place );

    return place;
  }
 
开发者ID:coderoshi,项目名称:glass,代码行数:25,代码来源:PlaceUtils.java

示例4: exchangeAuthorizationForToken

import com.google.api.client.json.JsonParser; //导入方法依赖的package包/类
public OauthToken exchangeAuthorizationForToken(String code, String clientId, String clientSecret, Map<String, Object> options) throws DnsimpleException, IOException {
  Map<String, Object> attributes = new HashMap<String, Object>();
  attributes.put("code", code);
  attributes.put("client_id", clientId);
  attributes.put("client_secret", clientSecret);
  attributes.put("grant_type", "authorization_code");

  if (options.containsKey("state")) {
    attributes.put("state", options.remove("state"));
  }

  if (options.containsKey("redirect_uri")) {
    attributes.put("redirect_uri", options.remove("redirect_uri"));
  }

  HttpResponse response = client.post("oauth/access_token", attributes);
  InputStream in = response.getContent();
  if (in == null) {
    throw new DnsimpleException("Response was empty", null, response.getStatusCode());
  } else {
    try {
      JsonParser jsonParser = GsonFactory.getDefaultInstance().createJsonParser(in);
      return jsonParser.parse(OauthToken.class);
    } finally {
      in.close();
    }
  }
}
 
开发者ID:dnsimple,项目名称:dnsimple-java,代码行数:29,代码来源:OauthEndpoint.java

示例5: expectClient

import com.google.api.client.json.JsonParser; //导入方法依赖的package包/类
/**
 * Return a Client that is configured to expect a specific URL, HTTP method, request attributes, and HTTP headers.
 *
 * @param expectedUrl The URL string that is expected
 * @param expectedMethod The HTTP method String that is expected
 * @param expectedHeaders a Map<String, Object> of headers
 * @param expectedAttributes A map of values as attributes
 * @return The Client instance
 */
public Client expectClient(final String expectedUrl, final String expectedMethod, final Map<String, Object> expectedHeaders, final Object expectedAttributes) {
  Client client = new Client();

  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      assertEquals(new GenericUrl(expectedUrl), new GenericUrl(url));
      assertEquals(expectedMethod, method);

      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          if (!getContentAsString().equals("")) {
            JsonParser jsonParser = GsonFactory.getDefaultInstance().createJsonParser(getContentAsString());
            Map<String,Object> attributes = jsonParser.parse(GenericJson.class);
            assertEquals(expectedAttributes, attributes);
          }

          for (Map.Entry<String, Object> expectedHeader : expectedHeaders.entrySet()) {
            assertEquals(expectedHeader.getValue(), getHeaders().get(expectedHeader.getKey()));
          }

          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          return mockResponse(response, resource("pages-1of3.http"));
        }
      };
    }
  };

  client.setTransport(transport);

  return client;
}
 
开发者ID:dnsimple,项目名称:dnsimple-java,代码行数:43,代码来源:DnsimpleTestBase.java

示例6: instance

import com.google.api.client.json.JsonParser; //导入方法依赖的package包/类
public static Instance instance(String resourcePath) {
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    try {
        JsonParser parser = jsonFactory
                .createJsonParser(new FileInputStream(Resources.getResource(resourcePath).getFile()));
        return parser.parse(Instance.class);
    } catch (Exception e) {
        throw new RuntimeException("failed to load Instance json file " + resourcePath + ": " + e.getMessage(), e);
    }
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:11,代码来源:TestInstanceToMachine.java

示例7: parseAndClose

import com.google.api.client.json.JsonParser; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Object parseAndClose(InputStream in, Charset charset, Type dataType) throws IOException {
  JsonParser parser = getJsonFactory().createJsonParser( in, charset );
  initializeParser( parser );
  return parser.parse( dataType, true, customParser );
}
 
开发者ID:icoretech,项目名称:audiobox-jlib,代码行数:10,代码来源:AudioBoxObjectParser.java


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