我有一系列商品,其格式如下:
[
{
"text": "Title 1",
"value": "1"
}
{
"text": "Title 2",
"value": "2"
}
]
我有一个从该数组返回value
的函数。我需要使用该值从数组中获取文本。因此,如果我有1
,那么我需要搜索数组并检索Title 1
对要搜索的正确术语不满意?
答案 0 :(得分:1)
您需要创建某种搜索功能。下面的函数在o.value
的数组结构对象列表中找到param1
的{{1}}的所有元素。您可以进一步扩展此示例,以仅返回数组的一个元素,或返回param2
的集合。
o.text
答案 1 :(得分:0)
只需更新TaurusHORN答案,然后将其缩短即可。
webView.setDownloadListener(new DownloadListener()
{
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimeType,
long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(
Uri.parse(url));
request.setMimeType(mimeType);
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading File...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(
url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_LONG).show();
}});