简体   繁体   English

iPhone如何与JSON文件一起发送大图像? 我应该将其嵌入JSON中还是单独发送?

[英]iPhone how to send a large image along with a JSON file? Should I embed it within the JSON or send separately?

I'm trying to create a way to save the interface of my app in a JSON file. 我正在尝试创建一种方法来保存我的应用程序的界面在JSON文件中。 While static elements I can define by their frames and/or center points, the interface does include a single image selected from the photo library. 虽然静态元素我可以通过它们的框架和/或中心点来定义,但是界面确实包括从照片库中选择的单个图像。 Because some iPhones have 8MP cameras, I can anticipate that some images would be very large. 因为有些iPhone有800万像素的摄像头,我可以预见到一些图像会非常大。

I would like to be able to save this interface and send it over by email, so another app user can re-open the file and see the same interface with the image included. 我希望能够保存此界面并通过电子邮件发送,因此另一个应用程序用户可以重新打开该文件并查看包含图像的相同界面。

Currently I'm using JSONKit to save my data into a JSON object. 目前我正在使用JSONKit将我的数据保存到JSON对象中。 This means that the email will contain a single JSON file containing both the layout parameters and the image. 这意味着该电子邮件将包含一个包含布局参数和图像的JSON文件。 I've never worked with such large JSON files, so the question is - will having several megs of image data within JSON present parsing issues? 我从来没有使用过这么大的JSON文件,所以问题是 - 在JSON中会有几个megs的图像数据存在解析问题吗? Or should I select some other file container that would have : first part JSON file, second part raw image data and then separate that file into a JSON string and a raw data string? 或者我应该选择一些其他文件容器:第一部分JSON文件,第二部分原始图像数据,然后将该文件分成JSON字符串和原始数据字符串?

This is what I'm using currently to get a JSON file. 这就是我目前用来获取JSON文件的内容。 After adding NSData to JSON, the convert to json method returns nil 将NSData添加到JSON后,转换为json方法返回nil

    NSString* currentURL = webView.request.mainDocumentURL.absoluteString;
    [dictionary setValue:currentURL forKey:@"webViewAddress"];

//this call correctly returns the json string
    NSLog(@"%@", [dictionary JSONString]);
    NSLog(@"+++++++++++++++++++++++++++++++++++++");
    NSData* imageData = UIImagePNGRepresentation(arOverlayView.image);
//after this call, the json returns nil
    [dictionary setValue:imageData forKey:kimageData];
      NSLog(@"%@", [dictionary JSONString]); 

If you are using email as a transport mechanism, your binary data will have to end up as something like Base64 encoded at some point in its life. 如果您使用电子邮件作为传输机制,那么您的二进制数据必须在其生命中的某个时刻以Base64编码的方式结束。 There is no "raw" format for email, there is only text. 电子邮件没有“原始”格式,只有文本。

At best you could implement Base85 encoding which is more efficient than Base64 最多可以实现Base85编码,这比Base64更有效

So you are going to have to suck up the large file sizes unless you invent your own transport mechanism - such as a point to point TCP/IP based link. 因此,除非您发明自己的传输机制(例如基于TCP / IP的点对点链接),否则您将不得不吸收大文件大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM