我有一些数据,需要用这个结构创建一个 json 文件:
{"eventData":{"eventDate":"Jun 13, 2012 12:00:00 AM","eventLocation":{"latitude":43.93838383,"longitude":-3.46},"text":"hjhj","imageData":"raw data","imageFormat":"JPEG","expirationTime":1339538400000},"type":"ELDIARIOMONTANES","title":"accIDENTE"}
请有人给我一些代码如何将我的数据放入具有这种结构的 json 文件中,或者至少是一个关于你如何制作 json 结构的示例?
编辑
好的,所以我写了一些代码:
NSString *jsonString = @"[{\"eventData\":{\"eventDate\":\"Jun 13, 2012 12:00:00 AM\",\"eventLocation\":{\"latitude\":43.93838383,\"longitude\":-3.46},\"text\":\"hjhj\",\"imageData\":\"raw data\",\"imageFormat\":\"JPEG\",\"expirationTime\":1339538400000},\"type\":\"ELDIARIOMONTANES\",\"title\":\"accIDENTE\"}]";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *e;
NSMutableArray *jsonList = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&e];
NSLog(@"jsonList: %@", jsonList);
jsonList 现在是一个 json 文件???它的格式是否正确?因为当我打印它时,输出是:
jsonList: (
{
eventData = {
eventDate = "Jun 13, 2012 12:00:00 AM";
eventLocation = {
latitude = "43.93838383";
longitude = "-3.46";
};
expirationTime = 1339538400000;
imageData = "raw data";
imageFormat = JPEG;
text = hjhj;
};
title = accIDENTE;
type = ELDIARIOMONTANES;
}
)