编码网址 -
https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select%20*%20where%20((A%20%3D%20201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
解码的网址 -
https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select * where ((A= 201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
在 URI 生成器中,我们应该使用哪个 URL 进行编码或解码?
此外,给定的代码不起作用:-
String xyz="1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU";
String X="201";
final String STUDENT_RECORD_URL="https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select*where";
final String Frag1 = "A";
final String Frag2 = "key";
Builder builder = Uri.parse(STUDENT_RECORD_URL).buildUpon();
builder.appendQueryParameter(Frag1,X);
builder.appendQueryParameter(Frag2,xyz);
String finalUri=builder.build().toString();
我认为您误解了查询参数是什么。它们都应该是 url 中的键值对。对于您的 url https://spreadsheets.google.com/tq?tqx=out:JSON&tq=select * where ((A= 201))&key=1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU
,构建它看起来像:
final String STUDENT_RECORD_URL="https://spreadsheets.google.com/tq";
Builder builder = Uri.parse(STUDENT_RECORD_URL).buildUpon();
builder.appendQueryParameter("txq", "out:JSON");
builder.appendQueryParameter("tq", "select * where ((A= 201))");
builder.appendQueryParameter("key", "1424bS7kU8nJbHdu4QdoAFdIdWDSnmEnj2NqfMb6rPTU");
String finalUri = builder.build().toString();
appendQueryParameter
方法将自动对您的参数进行 url 编码。