【问题标题】:How to MQL query string into Tranlated URL?如何将 MQL 查询字符串转换为翻译后的 URL?
【发布时间】:2011-02-04 17:41:19
【问题描述】:

http://api.geoapi.com/v1/q

我的查询:{"lat": 37.75629, "lon": -122.4213, "radius": "1km", "entity": [{"type": "business", "guid": null}]}
http://api.geoapi.com/v1/q?q=%7B%22lat%22%3A+37.75629%2C+%22lon%22%3A+-122.4213%2C+%22radius%22%3A+%221km%22%2C+%22entity%22%3A+%5B%7B%22type%22%3A+%22business%22%2C+%22guid%22%3A+null%7D%5D%7D&apikey=demo&pretty=1

我目前正在开发安卓系统。如何将查询字符串转换为解析后的 URL。是否有任何工具翻译网址?否则我想实现逻辑。我不知道我的问题是对还是错?谁能帮帮我。

【问题讨论】:

    标签: android mql geoapi


    【解决方案1】:

    如果我理解你的问题,在 Android 上,你可以使用

    Uri uri=Uri.parse(url_as_string);
    uri.getQueryParameter("param1");
    

    或 Apache 库提供查询解析器:

    http://developer.android.com/reference/org/apache/http/client/utils/URLEncodedUtils.htmlhttp://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/utils/URLEncodedUtils.html

    方法 parse() 返回从 URI 的查询部分构建的 NameValuePairs 列表。

    如果要将参数转换为 uri,请使用 Uri.Builder:

    Uri.Builder uri = new Uri.Builder().scheme("http").
            authority("test.com").
            path("theservlet").
            appendQueryParameter("q", theQuery);
    

    感谢Willdiyism 提供信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多