gpt4 book ai didi

iphone - 如何使用Three20框架上传多个图像并处理JSON响应?

转载 作者:行者123 更新时间:2023-12-03 19:12:44 26 4
gpt4 key购买 nike

所以我有一个 iPhone 应用程序需要:

  1. 将多个字符串和最多 5 个图像(存储在内存中)发布到 RoR Web 应用程序
  2. 解析返回的 JSON,其中包含多个字符串和一组 URL(每个 URL 代表上传图像在网站上的位置)。

问题:

  1. 这可以用 Three20 来完成吗(很好,因为我正在用它来做其他事情)?如果是这样,怎么办?

  2. 如果用 Three20 无法完成...如何使用 ASIHttpRequest 来完成?或者如果这是更好的选择,也许可以将某些内容嵌入到 SDK 中?

非常感谢

最佳答案

不幸的是,网络上没有大量关于 Three20 的教程和良好的文档......所以这就是我最终如何让事情发挥作用的:

- (void) sendToWebsite {

NSString* url = [[NSString stringWithFormat:kRequestURLPath, self.entityId] stringByAppendingString:@".json"] ;

// Prep. the request
TTURLRequest* request = [TTURLRequest requestWithURL: url delegate: self];
request.httpMethod = @"POST";
request.cachePolicy = TTURLRequestCachePolicyNoCache;

// Response will be JSON ... BUT WHY DO I NEED TO DO THIS HERE???
request.response = [[[TTURLJSONResponse alloc] init] autorelease];

// Set a header value
[request setValue:[[UIDevice currentDevice] uniqueIdentifier] forHTTPHeaderField:@"Device-UID"];

// Post a string
[request.parameters setObject:self.entity_title forKey:@"entity_title"];

// Post some images
for (int i = 0; i < [self.photos count]; i++) {
// IS IT POSSIBLE TO ADD A PARAM NAME SO I CAN LOOK FOR THE SAME NAME
// IN THE WEB APPLICATION REGARDLESS OF FILENAME???
[request addFile:UIImagePNGRepresentation([self.winnerImages objectAtIndex:i])
mimeType:@"image/png"
fileName:[NSString stringWithFormat:@"photo_%i.png", i]];
}

// You rails guys will know what this is for
[request.parameters setObject:@"put" forKey:@"_method"];

// Send the request
[request sendSynchronously];

}

我仍然不明白(或发现有问题)的事情:

  1. 对于已发布的文件,如何同时包含参数名称和文件名?
  2. 设置 request.response = 的目的是什么?我不明白。

关于iphone - 如何使用Three20框架上传多个图像并处理JSON响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2816033/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com