快照值顺序由SwiftyJSON更改,返回[null,nulll,.... items]

时间:2019-05-16 09:04:30

标签: ios swift firebase firebase-realtime-database swifty-json

我正在使用Firebase,正在进行查询并获取数据。然后在JSON中进行了介绍,在此之后,JSON的数据顺序发生了变化,这不是什么问题,我不要顺序应该改变。

做出相同订单的解决方案是什么 这是我的数据

//Query Applied
  pathref.queryOrderedByKey().queryStarting(atValue: fromItemKey).queryLimited(toFirst: UInt(paginationCount)).observe(.value, with: { (snapshot) in {

     print(" json obj=====",snapshot.value  )
    // all order is correct 

     let jsonData = try JSONSerialization.data(withJSONObject: bizOfferingsSnapshot.value as Any, options: .prettyPrinted)

     let offeringJson = try JSON(data: jsonData)

    // here order is changed 
      print(" json obj=====",offeringJson  )
        }

快照数据样本

       Optional({
            20 =     {
                bizOfferingsHeaderTypeThree =         {
                    headerText = Fruits;
                    indexOrder = 1;
                    isVisible = 1;
                };
                bizOfferingsID = "Fruits_20";
                description = "";
                imageStoragePathList =         (
                    "MUSKMELON.png"
                );
                isVisible = 1;
                itemQunatitySelected = 0;
                itemRetailInfo =         {
                    quantityPrice =             (
                                        {
                            discountPrice = 0;
                            isEditable = 0;
                            quantity = 1000;
                            quantitySelected = 1000;
                            regularPrice = 18;
                        }
                    );
                    units = GRAMS;
                };
                masterImage = 0;
                primaryText = Muskmelon;
                totalCountQunatity = 0;
                vegNonVegInfoEnum = NONE;
            };
            21 =     {
                bizOfferingsHeaderTypeThree =         {
                    headerText = Fruits;
                    indexOrder = 1;
                    isVisible = 1;
                };
                bizOfferingsID = "Fruits_21";
                description = "";
                imageStoragePathList =         (
                    "ORANGES_IMPORTED.png"
                );
                isVisible = 1;
                itemQunatitySelected = 0;
                itemRetailInfo =         {
                    quantityPrice =             (
                                        {
                            discountPrice = 0;
                            isEditable = 0;
                            quantity = 500;
                            quantitySelected = 500;
                            regularPrice = "117.5";
                        }
                    );
                    units = GRAMS;
                };
                masterImage = 0;
                primaryText = "Oranges Imported";
                totalCountQunatity = 0;
                vegNonVegInfoEnum = NONE;
            };
            22 =     {
                bizOfferingsHeaderTypeThree =         {
                    headerText = Fruits;
                    indexOrder = 1;
                    isVisible = 1;
                };
                bizOfferingsID = "Fruits_22";
                description = "";
                imageStoragePathList =         (
                    "MUSK_MELON_MADHUMATHI.png"
                );
                isVisible = 1;
                itemQunatitySelected = 0;
                itemRetailInfo =         {
                    quantityPrice =             (
                                        {
                            discountPrice = 0;
                            isEditable = 0;
                            quantity = 1000;
                            quantitySelected = 1000;
                            regularPrice = 39;
                        }
                    );
                    units = GRAMS;
                };
                masterImage = 0;
                primaryText = "Musk Melon Madhumathi";
                totalCountQunatity = 0;
                vegNonVegInfoEnum = NONE;
            };
            23 =     {
                bizOfferingsHeaderTypeThree =         {
                    headerText = Fruits;
                    indexOrder = 1;
                    isVisible = 1;
                };
                bizOfferingsID = "Fruits_23";
                description = "";
                imageStoragePathList =         (
                    "APPLE_FUZI.png"
                );
                isVisible = 1;
                itemQunatitySelected = 0;
                itemRetailInfo =         {
                    quantityPrice =             (
                                        {
                            discountPrice = 0;
                            isEditable = 0;
                            quantity = 500;
                            quantitySelected = 500;
                            regularPrice = "104.5";
                        }
                    );
                    units = GRAMS;
                };
                masterImage = 0;
                primaryText = "Apple Fuzi";
                totalCountQunatity = 0;
                vegNonVegInfoEnum = NONE;
            };
            24 =     {
                bizOfferingsHeaderTypeThree =         {
                    headerText = Fruits;
                    indexOrder = 1;
                    isVisible = 1;
                };
                bizOfferingsID = "Fruits_24";
                description = "";
                imageStoragePathList =         (
                    "APPLE_ROYAL_GALA_PACK_OF_4_NOS.png"
                );
                isVisible = 1;
                itemQunatitySelected = 0;
                itemRetailInfo =         {
                    quantityPrice =             (
                                        {
                            discountPrice = 0;
                            isEditable = 0;
                            quantity = 1;
                            quantitySelected = "0.1";
                            regularPrice = 99;
                        }
                    );
                    units = PIECES;
                };
                masterImage = 0;
                primaryText = "Apple Royal Gala Pack of 4 Nos";
                totalCountQunatity = 0;
                vegNonVegInfoEnum = NONE;
            };
            25 =     {
                bizOfferingsHeaderTypeThree =         {
                    headerText = Fruits;
                    indexOrder = 1;
                    isVisible = 1;
                };
                bizOfferingsID = "Fruits_25";
                description = "";
                imageStoragePathList =         (
                    "Fruits/KIWI.png"
                );
                isVisible = 1;
                itemQunatitySelected = 0;
                itemRetailInfo =         {
                    quantityPrice =             (
                                        {
                            discountPrice = 0;
                            isEditable = 0;
                            quantity = 1;
                            quantitySelected = "0.1";
                            regularPrice = 25;
                        }
                    );
                    units = PIECES;
                };
                masterImage = 0;
                primaryText = Kiwi;
                totalCountQunatity = 0;
                vegNonVegInfoEnum = NONE;
            };

转换为JSON数据顺序后的数据样本

 {
      "24" : {
        "masterImage" : 0,
        "imageStoragePathList" : [
          "APPLE_ROYAL_GALA_PACK_OF_4_NOS.png"
        ],
        "itemRetailInfo" : {
          "quantityPrice" : [
            {
              "regularPrice" : 99,
              "isEditable" : false,
              "discountPrice" : 0,
              "quantitySelected" : 0.10000000000000001,
              "quantity" : 1
            }
          ],
          "units" : "PIECES"
        },
        "bizOfferingsID" : "Fruits_24",
        "itemQunatitySelected" : 0,
        "totalCountQunatity" : 0,
        "primaryText" : "Apple Royal Gala Pack of 4 Nos",
        "isVisible" : true,
        "description" : "",
        "bizOfferingsHeaderTypeThree" : {
          "indexOrder" : 1,
          "headerText" : "Fruits",
          "isVisible" : true
        },
        "vegNonVegInfoEnum" : "NONE"
      },
      "29" : {
        "masterImage" : 0,
        "imageStoragePathList" : [
          "THAI_GUAVA_IMPORTED.png"
        ],
        "itemRetailInfo" : {
          "quantityPrice" : [
            {
              "regularPrice" : 59.5,
              "isEditable" : false,
              "discountPrice" : 0,
              "quantitySelected" : 500,
              "quantity" : 500
            }
          ],
          "units" : "GRAMS"
        },
        "bizOfferingsID" : "Fruits_29",
        "itemQunatitySelected" : 0,
        "totalCountQunatity" : 0,
        "primaryText" : "Thai Guava (Imported)",
        "isVisible" : true,
        "description" : "",
        "bizOfferingsHeaderTypeThree" : {
          "indexOrder" : 1,
          "headerText" : "Fruits",
          "isVisible" : true
        },
        "vegNonVegInfoEnum" : "NONE"
      },
      "25" : {
        "masterImage" : 0,
        "imageStoragePathList" : [
          "Fruits\/KIWI.png"
        ],
        "itemRetailInfo" : {
          "quantityPrice" : [
            {
              "regularPrice" : 25,
              "isEditable" : false,
              "discountPrice" : 0,
              "quantitySelected" : 0.10000000000000001,
              "quantity" : 1
            }
          ],
          "units" : "PIECES"
        },
        "bizOfferingsID" : "Fruits_25",
        "itemQunatitySelected" : 0,
        "totalCountQunatity" : 0,
        "primaryText" : "Kiwi",
        "isVisible" : true,
        "description" : "",
        "bizOfferingsHeaderTypeThree" : {
          "indexOrder" : 1,
          "headerText" : "Fruits",
          "isVisible" : true
        },
        "vegNonVegInfoEnum" : "NONE"
      },
      "28" : {
        "masterImage" : 0,
        "imageStoragePathList" : [
          "TAMARIND_SWEET_PACK_OF_250_G.png"
        ],
        "itemRetailInfo" : {
          "quantityPrice" : [
            {
              "regularPrice" : 90,
              "isEditable" : false,
              "discountPrice" : 0,
              "quantitySelected" : 0.10000000000000001,
              "quantity" : 1
            }
          ],
          "units" : "PIECES"
        },
        "bizOfferingsID" : "Fruits_28",
        "itemQunatitySelected" : 0,
        "totalCountQunatity" : 0,
        "primaryText" : "Tamarind Sweet Pack of 250 g",
        "isVisible" : true,
        "description" : "",
        "bizOfferingsHeaderTypeThree" : {
          "indexOrder" : 1,
          "headerText" : "Fruits",
          "isVisible" : true
        },
        "vegNonVegInfoEnum" : "NONE"
      },
      "22" : {
        "masterImage" : 0,
        "imageStoragePathList" : [
          "MUSK_MELON_MADHUMATHI.png"
        ],
        "itemRetailInfo" : {
          "quantityPrice" : [
            {
              "regularPrice" : 39,
              "isEditable" : false,
              "discountPrice" : 0,
              "quantitySelected" : 1000,
              "quantity" : 1000
            }
          ],
          "units" : "GRAMS"
        },
        "bizOfferingsID" : "Fruits_22",
        "itemQunatitySelected" : 0,
        "totalCountQunatity" : 0,
        "primaryText" : "Musk Melon Madhumathi",
        "isVisible" : true,
        "description" : "",
        "bizOfferingsHeaderTypeThree" : {
          "indexOrder" : 1,
          "headerText" : "Fruits",
          "isVisible" : true
        },
        "vegNonVegInfoEnum" : "NONE"
      },
      "26" : {
        "masterImage" : 0,
        "imageStoragePathList" : [
          "CUSTARD_APPLE.png"
        ],
        "itemRetailInfo" : {
          "quantityPrice" : [
            {
              "regularPrice" : 44.5,
              "isEditable" : false,
              "discountPrice" : 0,
              "quantitySelected" : 500,
              "quantity" : 500
            }
          ],
          "units" : "GRAMS"
        },
        "bizOfferingsID" : "Fruits_26",
        "itemQunatitySelected" : 0,
        "totalCountQunatity" : 0,
        "primaryText" : "Custard Apple",
        "isVisible" : true,
        "description" : "",
        "bizOfferingsHeaderTypeThree" : {
          "indexOrder" : 1,
          "headerText" : "Fruits",
          "isVisible" : true
        },
        "vegNonVegInfoEnum" : "NONE"
      }

有时候我会 [   空值,   空值,   空值,   空值,   空值,   空值,   空值,   空值,   空值,   空值,   {字典} ]为什么我要得到null,甚至在向ison求助后获得10个项目的快照也得到快照,而前10个结果为null,则为

0 个答案:

没有答案
相关问题