1
如何将NSArray或NSDictionary的值传递给JSON.Its可能与否。现在我已经完成NSDictionary值和NSArray值转换为JSON.But我与PHP连接我的PHP代码具有编码和解码方法与编码和解码如何可以从JSON获得我的回复吗?以及如何从该响应中获取值?将NSDictionary或NSArray POST成JSON?
我试图转换JSON格式以下代码::
// Empty array
NSArray *emptyArray = @[];
// Single element array
NSArray *singleElementArray = @[@"Error Message"];
// Array of strings
NSArray *arrayOfStrings = @[@"First Name", @"Last Name"];
// Array of above arrays
NSArray *arrayOfObjects = @[emptyArray, singleElementArray, arrayOfStrings];
// Dictionary with several kay/value pairs and the above array of arrays
NSDictionary *dict = @{@"BlogName" : @"iOS Developer Tips",
@"BlogDomain" : @"iOSDeveloperTips.com",
@"Array" : arrayOfObjects};
NSError *error = nil;
NSData *json;
// Dictionary convertable to JSON ?
if ([NSJSONSerialization isValidJSONObject:dict])
{
// Serialize the dictionary
json = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
NSLog(@"json: %@", json);
// If no errors, let's view the JSON
if (json != nil && error == nil)
{
NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
NSLog(@"JSON conversion: %@", jsonString);
}
}
我从jsonString。我正确的价值观有发布此字符串JSON POST方法其工作正常,但我需要的NSDictionary的NSArray或后有到JSON.HOW?
你需要证明什么是你的NSArray和你想要的JSON是什么样子。对于一个模糊的问题,答案太多了。 – 2015-02-09 13:21:53