Iphone 如何使用jsonkit将中的数据数组转换为json?

Iphone 如何使用jsonkit将中的数据数组转换为json?,iphone,ios,Iphone,Ios,我越来越像这样了 [Hello] [;] [hi] [;] [Its there] [;] [Welcome] [;] [Hello] [;] 我想转换为json格式,我不知道如何将数据数组转换为json。请帮助我您需要使用以下代码 NSDictionary *dict = [myJsonString JSONValue]; 如果它不起作用,则使用以下命令 // // we begin with our string in json format // NSString *jso

我越来越像这样了

 [Hello] [;]
 [hi] [;]
 [Its there] [;]
 [Welcome] [;]
 [Hello] [;]

我想转换为json格式,我不知道如何将数据数组转换为json。请帮助我

您需要使用以下代码

NSDictionary *dict = [myJsonString JSONValue];
如果它不起作用,则使用以下命令

// 
// we begin with our string in json format
//
NSString *jsonString = [[NSString alloc] initWithString:@"{\"1\":\"1: Rossy Robinson - $25\",\"2\":\"7: Davey Ambrose - $25\",\"3\":\"14: Ross Robinson - $25\"}"];

//
// convert the json string to an NSMutableDictionary
//
NSError *e;
NSMutableDictionary *JSONdic = [NSJSONSerialization JSONObjectWithData: [jsonString dataUsingEncoding: NSUTF8StringEncoding] options: NSJSONReadingMutableContainers error: &e];

//
// change a value and add a new value in the dict
//
NSLog(@"before: object for key 1 is: %@", [JSONdic objectForKey:@"1"]);
[JSONdic setObject:@"xxx" forKey:@"1"];
[JSONdic setObject:@"Phil McQuitty" forKey:@"2"];

//
//convert dictionary object to json data
//
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:JSONdic options:NSJSONWritingPrettyPrinted error:&e];

//
// convert the json data back to a string
//
NSString *jsonText = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];\

//
// print out the final results
//
NSLog(@"back to string: %@", jsonText);

向我们展示您为此编写的输入字符串和代码。这一程序行对我非常有用。我有一个textile中的数据,如何分配objectkey以及如何转换为json格式,以便将值存储到服务器中。我不明白您的问题?我有一个info.txt中的数据,如何分配objectkey以及如何转换为Json格式,以便将字符串值存储到服务器中,您需要从NSBundle获取值,然后获取详细信息,然后可以获取字符串,然后应用jsonkit函数