Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在iPhone中插入更多密钥_Objective C_Xcode - Fatal编程技术网

Objective c 在iPhone中插入更多密钥

Objective c 在iPhone中插入更多密钥,objective-c,xcode,Objective C,Xcode,如何向json文件添加多个密钥 NSArray *keys = [NSArray arrayWithArray:allkeys]; NSArray *objects = [NSArray arrayWithArray:allobjects]; NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; 正如您在上面看到的,键foreJsonDictionary是键,但是我想

如何向json文件添加多个密钥

NSArray *keys = [NSArray arrayWithArray:allkeys];
NSArray *objects = [NSArray arrayWithArray:allobjects];

NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
正如您在上面看到的,键foreJsonDictionary是键,但是我想要一个包含更多键的键。我尝试了“forKeys:keys,keys2”(keys2)另一个数组,但不起作用。现在的结果是:

{"text2":"Untitled {{400, 100}, {200, 100}} <UICFFont: 0x2c3960> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12px","text3":"Untitled {{400, 100}, {200, 100}} <UICFFont: 0x2c3960> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12px","text1":"Untitled {{400, 100}, {200, 100}} <UICFFont: 0x2c3960> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size:     12px"}

提前感谢您的帮助

您必须创建嵌套NSDictionary的层次结构才能实现您想要做的事情

大概是这样的:

{  
"menu": {  
    "header": "xProgress SVG Viewer",  
    "items": [  
        {  
            "id": "Open"  
        },  
// the following objecst are just dummies, fill this with your own objects
NSArray *objectArray = [NSArray arrayWithOjects:obj1,obj2,obj3,nil];
NSArray *keyArray = [NSArray arrayWithOjects:@"key1",@"key2,@"key3",nil];

NSDictionary *subDict = [NSDictionary dictionaryWithObjects:objectArray forKeys:keyArray];

// now create the main dictionary, which will hold your sub dictionary for one key
objectArray = [NSArray arrayWithObjects:,subDict,someObject,@"just a string"];
keyArray = [NSArray arrayWithObjects:@"first key",@"second key",@"third key"];

NSDictionary *mainDict = [NSDictionary dictionaryWithObjects:objectArray forKeys:keyArray];
您的示例JSON将具有以下结构:

带有键“menu”的NSDictionary,其中包含另一个NSDictionary。此字典具有键“header”,其中包含字符串,键“items”中包含NSDictionary数组