React Native JSONSerialization

时间:2017-02-03 20:09:59

标签: objective-c serialization react-native

我有一个NSDictionary

   address =     {
        address1 = "Ivy House";
        address2 = "Sandy Lane";
        city = Rush;
        country = Ireland;
        county = Dublin;
        email = "notknown@whatever.com";
        mobile = "<null>";
        postCode = "<null>";
        smsAlert = "<null>";
        telephone = 18437584;
        websiteAddress = "www.example.com";
    };

我需要传递这个以将native作为launchOptions进行响应,它接受JSON为这种格式。 (行情和=替换为:等)

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"spotlight"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];

JSON

"address":
       {
           "address1": "Ivy House",
           "address2": "Sandy Lane",
           "city": "Rush",
           "postCode": null,
           "email": "notknown@whatever.com",
           "telephone": "18437584",
           "mobile": null,
           "smsAlert": null,
           "county": "Dublin",
           "country": "Ireland",
           "websiteAddress": "www.example.com"
       },

转换字典的最佳方法是什么,以便本机接受它?

1 个答案:

答案 0 :(得分:0)

将地址设置为constvar,并将其余代码标记为具有相同数字的格式,但格式为const。 例如:

    const address =     {
            address1: {
  }
}