转换的NSString的NSDictionary在Objective-C
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转换的NSString的NSDictionary在Objective-C相关的知识,希望对你有一定的参考价值。
这是我的字符串
{
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
Depth = 8;
Orientation = 1;
PixelHeight = 2848;
PixelWidth = 4288;
ProfileName = "Adobe RGB (1998)";
"{Exif}" = {
ColorSpace = 1;
ComponentsConfiguration = (
1,
2,
3,
0
);
DateTimeDigitized = "2011:03:12 16:17:25";
DateTimeOriginal = "2011:03:12 16:17:25";
ExifVersion = (
2,
2
);
ExposureBiasValue = 0;
ExposureProgram = 3;
ExposureTime = "0.000625";
FNumber = 4;
Flash = 0;
FlashPixVersion = (
1,
0
);
FocalLength = 26;
ISOSpeedRatings = (
200
);
LightSource = 14;
MaxApertureValue = 4;
MeteringMode = 5;
PixelXDimension = 4288;
PixelYDimension = 2848;
SceneCaptureType = 0;
SensingMethod = 2;
};
"{GPS}" = {
Latitude = "38.0374445";
LatitudeRef = N;
Longitude = "122.8031783333333";
LongitudeRef = W;
};
"{IPTC}" = {
DateCreated = 20110312;
DigitalCreationDate = 20110312;
DigitalCreationTime = 161725;
ObjectName = "DSC_0001";
TimeCreated = 161725;
};
"{JFIF}" = {
DensityUnit = 1;
JFIFVersion = (
1,
0,
1
);
XDensity = 72;
YDensity = 72;
};
"{TIFF}" = {
DateTime = "2011:05:03 20:30:44";
Make = "NIKON CORPORATION";
Model = "NIKON D90";
Orientation = 1;
PhotometricInterpretation = 2;
ResolutionUnit = 2;
Software = "QuickTime 7.7.1";
XResolution = 72;
YResolution = 72;
};
}
我想用下面的代码把它转换成的NSDictionary
NSData *myData = [myStr dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:myData
options:kNilOptions
error:&err];
但要在末尾的空
我的事问题是串甲...我怎样才能改变我的字符串格式将其转换成的NSDictionary
编辑:得到这个错误
Error Domain=NSCocoaErrorDomain Code=3840 "No string key for value in object around character 6." UserInfo={NSDebugDescription=No string key for value in object around character 6.}
任何一个请?
答案
这不是JSON;它看起来更像是从[NSDictionary description]
输出。
为了得到一些接近JSON,您需要:
- 将所有
=
字符:
,提供name : value
。 - 更改
;
元素之间,
。 - 更改所有阵列分隔符从
( ... )
到[ ... ]
。 - 添加双引号的所有非数值。
另一答案
尝试这个:
NSError *err = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData: myData options: NSJSONReadingMutableContainers error: &err];
以上是关于转换的NSString的NSDictionary在Objective-C的主要内容,如果未能解决你的问题,请参考以下文章
如何将 NSString 转换为 NSDictionary?
转换的NSString的NSDictionary在Objective-C
如果将一个NSObject从NSDictionary转换为NSString?