程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ipad-JSon對象創建plist請幫忙

ipad-JSon對象創建plist請幫忙

編輯:編程綜合問答
JSon對象創建plist請幫忙

這是Json對象,包含數組和object。我想要創建Plist,請指教

{
      "component":[
        {
          "id":1006,
          "name":"Image test 2",
          "child":[
            {
              "id":1101,
              "name":"component score mcq"
            },
            {
              "id":1105,
              "name":"component we score"
            },
            {
              "id":1095,
              "name":"a"
            },
            {
              "id":1103,
              "name":"component scq score"
            },
            {
              "id":1134,
              "name":"Hi this is my first blog from lesson"
            },
            {
              "id":1106,
              "name":"abc"
            },
            {
              "id":1102,
              "name":"component fitb score"
            },
            {
              "id":1096,
              "name":"testkrupsvideo"
            },
            {
              "id":1104,
              "name":"component either score"
            },
            {
              "id":1099,
              "name":"krupsblog updated"
            },
            {
              "id":1224,
              "name":"krupsforum updated"
            },
            {
              "id":1127,
              "name":"reading parent topic test"
            },
            {
              "id":1093,
              "name":"abc"
            },
            {
              "id":1128,
              "name":"ankit parent topic"
            },
            {
              "id":1129,
              "name":"test topic for component",
              "child":[
                {
                  "id":1228,
                  "name":"krupsud"
                },
                {
                  "id":1253,
                  "name":"06-12-2012 we updated"
                },
                {
                  "id":1130,
                  "name":"topic reading"
                },
                {
                  "id":1251,
                  "name":"06-12-2012 fitb"
                },
                {
                  "id":1225,
                  "name":"krupsvideo updated"
                },
                {
                  "id":1249,
                  "name":"06-12-2012 mcq"
                },
                {
                  "id":1250,
                  "name":"06-12-2012 scq"
                },
                {
                  "id":1226,
                  "name":"krupsaudio updated"
                },
                {
                  "id":1227,
                  "name":"krupsflash updated"
                },
                {
                  "id":1252,
                  "name":"06-12-2012 eo"
                }
              ]
            },
            {
              "id":1124,
              "name":"First dlr wiki for positive test",
              "child":[
                {
                  "id":1125,
                  "name":"Component wiki"
                }
              ]
            },
            {
              "id":1126,
              "name":"bhushan reading dlr"
            }
          ]
        }
      ]
    }

最佳回答:


將json串轉換成NSDictionary. 並將NSDictionary寫入到.plist文件

- (void)writeToPlist:(NSDictionary *)map {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    NSString *plistPath = [path stringByAppendingPathComponent:@"user-data.plist"];
    [map writeToFile:plistPath atomically:YES];
}


NSString *json=yourjsonstring;
NSDictionary *dict=[NSJSONSerialization JSONWithObjectWithData:[json dataUsingEncoding:NSUTF8StringEncoding]  options:NSJSONReadingMutableContainers error:nil];
[self writeToPlist:dict];
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved