ios 获得一个json串,解析之后如何保持顺序?
高洛峰
高洛峰 2017-04-17 17:54:57
0
3
456

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;
};

}

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
洪涛

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

小葫芦

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?

左手右手慢动作

If you want order, then use an array

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template