【问题标题】:Parse an image from json response Appcelerator Cloud?从 json 响应 Appcelerator Cloud 解析图像?
【发布时间】:2013-07-26 11:03:56
【问题描述】:

我正在使用 Appcelerator 云服务将图片上传到云端,并希望以各种尺寸取回它。上传工作正常,但我没有取回照片。我在 JSON 响应中收到 urls

这是我的代码:

    Cloud.Photos.show({
        photo_id: pid
    }, function (e) {
        if (e.success) {
            var photo = e.photos[0];
            waitDialog.hide();
            alert('Success:\n' +
                'id: ' + photo.id + '\n' +
                'filename: ' + photo.filename + '\n' +
                'updated_at: ' + photo.updated_at + '\n' +
                'urls: ' + photo.urls);

                alert(photo.urls.square);
                var image2 = photo.urls.square.toImage();

                var squareImage = Ti.UI.createImageView({
                    top: "10dp",
                    left: "10dp",
                    image: image2,
                    height: Titanium.UI.SIZE,
                    width: Titanium.UI.SIZE
                });

                $.index.add(squareImage);

        } else {
            alert('Error:\n' +
                ((e.error && e.message) || JSON.stringify(e)));
        }
    });

我收到这样的 JSON 响应(这不是原始的,因为我正在设备中测试它)

{
  "meta": {
    "status":"ok",
    "code":200,
    "method_name":"showPhoto"
  },
  "response": {
    "photos": [
      {
        "id":"4d51d4186f70952d4c000006",
        "filename":"photo.jpg",
        "size":584344,
        "collection_name":"default",
        "md5":"589b8ad43ed20bf8e622d719642bc939",
        "created_at":"2011-02-08T23:39:04+0000",
        "updated_at":"2011-02-08T23:39:08+0000",
        "processed":true,
        "content_type":"image/jpeg",
        "urls": {
          "square":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_square.jpg",
          "thumb":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_thumb.jpg",
          "small":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_small.jpg",
          "medium_500":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_medium_500.jpg",
          "medium_640":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_medium_640.jpg",
          "large":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_large.jpg",
          "original":"http://storage.appcelerator.com/c3e1d292cb79ba7b9783d6cd45344719/photos/4d51d4186f70952d4c000006/photo_original.jpg"
        }
      }
    ]
  } 
}

我想从urls获取所有图像。

我需要解析它还是我需要做的其他事情?谁能告诉我怎么做?

谢谢:)

【问题讨论】:

    标签: javascript android json titanium appcelerator


    【解决方案1】:

    这样分配照片

    squareImage.image =photo.urls.square;
    

    【讨论】:

    • 是的,我也试过了。问题是,photo.urls.square 没有返回任何东西。
    • 这是因为图像还没有被处理。看看文档。 docs.appcelerator.com/cloud/latest/#!/guide/… 您需要指定要同步的大小,以便立即可用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-18
    • 2018-11-12
    • 2013-03-27
    • 1970-01-01
    • 2011-07-03
    相关资源
    最近更新 更多