首页 > 解决方案 > Rails+Mongodb 使用 Swift 的反斜杠在 json 中获取对象

问题描述

我正在尝试从 swift 向 Rails+Mongodb 发送一个 json。我有一个带有字符串、整数和 2 个对象的 json。此对象 Fabrics 和 Palettes 嵌入在 WardrobeItem 中。

从 swift 我发送 Fabrics and Palettes 正确,没有反斜杠。

         let jsonPalettes = try! JSONEncoder().encode(itemsWardrobe[0].palettes)

         let jsonPString = String(data: jsonPalettes, encoding: .utf8)

         let definitePalettes = jsonPString!.replacingOccurrences(of: "\\", with: "")

在 Rails 控制台中,我得到 在此处输入图像描述

我的参数许可是

params.require(:wardrobe_items).permit(:name, :body_pos, :pattern, :season, :style, :clo_value, :layer, :last_worn_date, :washing,  :wardrobe_id, :category_id, :events_id => [], :subcategory_ids => [], palettes: [:id, :name_color,  :image_url, :color_palette_square], fabrics: [:id, :name])

我如何解决它?

标签: ruby-on-railsswiftmongodb

解决方案


推荐阅读