search

Home  >  Q&A  >  body text

ios 获得一个json串,解析之后如何保持顺序?

json类似如下,一般来说从网络得到的时候是一个nsdictionary,可以把它放到一个nsarray中以保持顺序不变,但是得到那个nsdicationary顺序会和json本身不一样么? 如何解决?

"All Shop" = 500;
dessert =     {
    All = 172;
    Barbeque = 44;
    Local = 53;
    Sids = 43;
};
drink =     {
    All = 84;
    Cafee = 31;
    Juice = 53;
};
fastFood =     {
    All = 246;
    Dumplings = 12;
    "Famous Brand" = 128;
    Noodes = 27;
    "Over Rice" = 115;
    "Pot Food" = 24;
};
feature =     {
    All = 138;
    Guangdong = 14;
    Muslim = 12;
    "Sea Food" = 58;
    Sichuan = 37;
    "Toast Fish" = 27;
};
foreigner =     {
    All = 43;
    Japan = 13;
    Korea = 25;
    Spaghetti = 1;
    West = 8;
};

}

高洛峰高洛峰2887 days ago464

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:56:57

    What you posted is not JSON

    Neither JSON nor NSDictonary guarantees that keys are in order
    So this is not a problem that needs to be "solved", you just need to not "create" problems by relying on things that are not guaranteed

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 17:56:57

    The order of Dictionary/JSON has nothing to do with the user. You can only use the key to get the Value. What does the order matter?

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:56:57

    If you want order, then use an array

    reply
    0
  • Cancelreply