-3

SBJson我最近尝试将我的应用程序中的 Json 库从NSJSONSerialization.

当我做这份工作时,我发现有一些我无法摆脱的关键价值。

这是NSDictionary我得到的一个例子NSJSONSerialization

 {

    id = 4028;

    "novel_author" = "XYZ";

    "novel_pub" = "ABC";

    "novel_title" = "DATE LIVE";

    updatedate = "2013-01-13 22:31:13";

    "vol_click" = 7563;

}

原始 Json 数据字符串为:

{
   "id":"4028",
   "vol_click":"7563",
   "updatedate":"2013-01-13 22:31:13",
   "novel_author":"XYZ",
   "novel_pub":"ABC",
   "novel_title":"DATE LIVE"
}

我无法获取键“id”的值。 [NSDictionary objectForKey@"id"]没用。

有没有人知道如何获得价值?

4

2 回答 2

0

As you can tell by the output of what looks like NSLog("%@", dict);, the JSON deserialization process works fine.

The dictionary contains a key called "id", so [dict objectForKey:@"id"] should also work fine.

I can only conclude that this isn't the actual cause of the trouble you're having.

于 2013-01-20T01:57:03.570 回答
0

这些中的任何一个都应该起作用:

        [yourDictName valueForKey:@"id"]
    [yourDictName objectForKey:@"id"]

如果您可以使用 NSLog 看到该值来显示字典,那么它就在那里。除此之外,请确保您的对象没有被 nil'd 或释放或释放。

于 2013-01-20T02:18:46.277 回答