在Android解析查询字符串 [英] Parsing query strings on Android

查看:238
本文介绍了在Android解析查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java EE的有<一个href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html">ServletRequest.getParameterValues().

Java EE has ServletRequest.getParameterValues().

在非EE平台,<一href="http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html#getQuery%28%29">URL.getQuery()简单地返回一个字符串。

On non-EE platforms, URL.getQuery() simply returns a string.

什么是正常的方式正确地解析查询字符串的URL时的没有的关于Java EE?

What's the normal way to properly parse the query string in a URL when not on Java EE?

&LT; 咆哮&GT;

这是问题的答案,试图使自己的解析器受欢迎。这是非常有趣和令人兴奋的微型编码的项目,但 我不能说这是一个好主意:(

It is popular in the answers to try and make your own parser. This is very interesting and exciting micro-coding project, but I cannot say that it is a good idea :(

下面的code段一般都是有缺陷或损坏,顺便说一句。打破他们是一个有趣的练习留给读者。 而到了黑客攻击使用它们的网站的。

The code snippets below are generally flawed or broken, btw. Breaking them is an interesting exercise for the reader. And to the hackers attacking the websites that use them.

解析查询字符串是一个明确的问题,但阅读的规格和理解的细微差别是不平凡的。这是远不如让一些平台库codeR做艰苦的工作,并做了固定,为您服务!

Parsing query strings is a well defined problem but reading the spec and understanding the nuances is non-trivial. It is far better to let some platform library coder do the hard work, and do the fixing, for you!

&LT; /咆哮&GT;

推荐答案

在Android上:

import android.net.Uri;

[...]

Uri uri=Uri.parse(url_string);
uri.getQueryParameter("para1");

这篇关于在Android解析查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆