Json字符串解码为不同的字符串值

Json字符串解码为不同的字符串值,json,Json,我有这样的JsonArray [ { "id": "60", "variant_id": "0", "name": "Grape Tomato- 150gm", "category": "10", "content": "{\"calories\":\"50\",\"carbohydrate\":\"\",\"fat\":\"\",\"protein\":\"\"}", "variant_si

我有这样的JsonArray

[
    {
        "id": "60",
        "variant_id": "0",
        "name": "Grape Tomato- 150gm",
        "category": "10",
        "content": "{\"calories\":\"50\",\"carbohydrate\":\"\",\"fat\":\"\",\"protein\":\"\"}",
        "variant_size": "",
        "types": "{\"ptype\":\"VG\"}",
        "price": "45 ",
        "discription": "<p>Grape tomatoes are hybrid tomatoes in smaller in size and sweet in taste. These are ideal to have especially in salads.</p>\n",
        "item_image": "userfile60.jpg",
        "graph_image": "graphfile60.png",
        "isVariant": "NO"
     },
如何将这些值转换为不同的字符串,以便使用它们来显示或使用饼图的值 例如:

String calories = "value" 
String carbohydrate= "value"
Sting fat ="value"
String Protein="value"

从上面的回答中。。我想获取此模式中的数据,请帮助。

为了好玩,请使用可编码协议以Swift回答。也许有人会开心

struct YourModel: Codable {
    let id: String
    let variant_id: String
    let name: String
    let category: String
    let content: Content
    let variant_size: String
    let types: Types
    let price: String
    let discription: String
    let item_image: String
    let graph_image: String
    let isVariant: String

    struct Types: Codable {
        let ptype: String
    }

    struct Content: Codable {
        let calories: String
        let carbohydrate: String
        let fat: String
        let protein: String
    }
}

let jsonData = "Your JSON".data(using: .utf8)!
let yourModelArray = try! JSONDecoder().decode([YourModel].self, from: jsonData)

您使用什么语言来解码JSON?
struct YourModel: Codable {
    let id: String
    let variant_id: String
    let name: String
    let category: String
    let content: Content
    let variant_size: String
    let types: Types
    let price: String
    let discription: String
    let item_image: String
    let graph_image: String
    let isVariant: String

    struct Types: Codable {
        let ptype: String
    }

    struct Content: Codable {
        let calories: String
        let carbohydrate: String
        let fat: String
        let protein: String
    }
}

let jsonData = "Your JSON".data(using: .utf8)!
let yourModelArray = try! JSONDecoder().decode([YourModel].self, from: jsonData)