for_2012 2013-08-02 05:39 采纳率: 0%
浏览 2202
已采纳

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"
            }
          ]
        }
      ]
    }
  • 写回答

1条回答 默认 最新

  • ReyZhang 移动开发领域新星创作者 2013-08-05 03:38
    关注

    将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];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体