将JSON数据存储到Realm db中,然后再返回

时间:2015-04-15 20:42:38

标签: ios json swift

出于某种原因,我努力尝试将一些JSON存储到我的Realm数据库中,然后再次将其作为JSON检索回来。我使用SwiftyJSON进行JSON解析,虽然它们是rawData()之前的旧版本。

所以我将JSON数组作为这样的字符串获取:

if let festivalNavArray = navDict["festivalInfo"]!.arrayValue {
  festMenu.string = festivalNavArray.description
}

然后存储到Realm中。但是当我试着读回来时:

let newJson = JSON(object: festMenu.string)
if let array = newJson.arrayValue {
   println("array")
}

它不再被识别为JSON数组。非常感谢任何帮助。

festMenu.string看起来像这样:

[[title: Food and Crafts, href: food-and-crafts, nav: [[title: Andy's Pancakes, href: andys-pancakes], [title: Sams Sushi, href: sams-sushi]]], [title: General Info, href: general-info, nav: [[title: About TOC Fest, href: about-toc-fest-2], [title: FAQs, href: faqs-2, nav: [[title: What To Bring/Not Bring, href: what-to-bringnot-bring], [title: RFID Wristband FAQ, href: rfid-wristband-faq], [title: Transportation FAQ, href: transportation-faq-2], [title: Ticketing FAQ, href: ticketing-faq-2], [title: Camping FAQ, href: camping-faq-2], [title: Concert FAQ, href: concert-faq-2], [title: General FAQ, href: general-faq-2], [title: Parking FAQ, href: parking-faq-2], [title: Accessibility, href: accessibility-2], [title: Directions, href: directions-2]]], [title: Getting There, href: getting-there], [title: Street Team Program, href: street-team-program-2], [title: Festival Map, href: festival-map-2], [title: Volunteering, href: volunteering], [title: Parking, href: parking-2]]], [title: News, href: news], [title: Ask Question, href: ask-question]]

0 个答案:

没有答案