仅获取 FileStack JSON.stringify 的 url 值? [英] Get only url value of FileStack JSON.stringify?

查看:45
本文介绍了仅获取 FileStack JSON.stringify 的 url 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上使用 FileStack,根据 FileStack Docs 我实际上有这个:

I'm using FileStack on my website, according to FileStack Docs I have this actually:

<iframe id="framefile" width="700" height="500" frameborder="0">
<p>Your browser does not support iframes.</p>
</iframe>
<div id="files"></div>

在 javascript 方面:

And in javascript side:

<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="http://api.filepicker.io/v2/filepicker.js"></script>

<script type="text/javascript">
filepicker.setKey("myAPIKey");
filepicker.pickMultiple(
  {
    mimetype: '*/*',
    language: 'es_mx',
    container: 'framefile',
    services: ['COMPUTER','GOOGLE_DRIVE','DROPBOX']
  },
  function(Blobs){
    console.log(JSON.stringify(Blobs));
  },
  function(FPError){
    console.log(FPError.toString());
  });
  </script>

我只需要获取 URL 文件值并将其放入 div.我试过这个:

I need to get only URL files values and put it in a div. I tried this:

<script type="text/javascript">
filepicker.setKey("myAPIKey");
filepicker.pickMultiple(
  {
    mimetype: '*/*',
    language: 'es_mx',
    container: 'framefile',
    services: ['COMPUTER','GOOGLE_DRIVE','DROPBOX']
  },
  function(Blobs){
    console.log(JSON.stringify(Blobs));
    var result = JSON.stringify(Blobs, ['url']);
    $('#files').html(result);
  },
  function(FPError){
    console.log(FPError.toString());
  });
</script>

我得到了这个:

[{"url":"https://cdn.filepicker.io/api/file/--link1--"}]

[{"url":"https://cdn.filepicker.io/api/file/--link1--"}]

但是如何以这种方式获取 URL 值?:

But How can I obtain URL values but in this way?:

https://cdn.filepicker.io/api/file/--link1--

有人有解决方案吗?

推荐答案

你快到了,不是吗?

如何将 [0].url 附加到返回的对象中?

What about appending [0].url to the object which is returned ?

我的意思是用 result = JSON.stringify(Blobs, ['url']); 代替 result = JSON.stringify(Blobs, ['url'])[0].网址;

I mean substituting result = JSON.stringify(Blobs, ['url']); for result = JSON.stringify(Blobs, ['url'])[0].url;

更新

我的第一个 anwser 是错误的,因为 result

My first anwser is wrong because result in

result = JSON.stringify(Blobs, ['url'])

返回'[{"url":"https://cdn.filepicker.io/api/file/--link1--"}]',因为它是一个字符串来自 stringify ed 变量.因此,result[0] 返回它的第一个字符,即 "[".最后 result[0].url 或者换句话说,"[".url 是未定义的.(而且几乎不可能)

returns '[{"url":"https://cdn.filepicker.io/api/file/--link1--"}]', which is a string since it comes from a stringifyed variable. Thus, result[0] returns its first character, which is "[". Finaly result[0].url or put differently, "[".url is undefined. (and can hardly be so)

更换这部分:

function(Blobs){
    console.log(JSON.stringify(Blobs));
    var result = JSON.stringify(Blobs, ['url']);
    $('#files').html(result);
}

function(Blobs){
    $('#files').html(Blobs[0].url);
}

如果想要从 json 中获取所需的信息,则不得stringify 它.

If one wants to get the desired information from a json, one must not stringify it.

更新

或者如果你想显示多个url,因为多个文件替换后一种方法

Or if you want to display numerous urls, because of multiple files replace the latter method by

function(Blobs){
    var displayedUrls = "";
    for (i = 0; i < Blobs.length; i++) { 
        displayedUrls += Blobs[i].url + "<br>";
    }
}
$('#files').html(displayedUrls);

这篇关于仅获取 FileStack JSON.stringify 的 url 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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