- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我目前正在尝试在 Xcode 中解码 Json,但我没有成功获得其中之一。
这是我得到的:
[
{
"id": "1",
"title": "bmw",
"price": "500.00",
"description": "330",
"addedDate": "2015-05-18 00:00:00",
"user_id": "1",
"user_name": "CANOVAS",
"user_zipCode": "32767",
"category_id": "1",
"category_label": "VEHICULES",
"subcategory_id": "2",
"subcategory_label": "Motos",
"bdd": {}
}
"pictures":
[
{ "name": "http://cars.axlegeeks.com/sites/default/files/4315/media/images/2014_BMW_Z4_sDrive28i_3790993.jpg"
}
]
}
]
我想为“图片”行获取“名称”的值,但出现错误“在展开值时意外发现 nil”。
对于其他值,我以这种方式进行:
let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as! NSDictionary
//Browse into JSON to get datas
let resp = jsonData["0"] as! NSDictionary
let user_nameR = resp["user_name"] as! String
let user_zipCodeR = resp["user_zipCode"] as! String
let titleR = resp["title"] as! String
let priceR = resp["price"] as! String
let descriptionR = resp["description"] as! String
谢谢你的帮助!
最佳答案
图片不在您的其他值所在的子词典中。这应该可行,但在强制转换之前,您应该检查所有值是否为 nil。
if let pictureArray = jsonData["pictures"] as? NSArray
{
if let pictureDict = pictureArray.firstObject as? NSDictionary
{
if let pictureName = pictureDict.objectForKey("name") as? String
{
NSLog("Picture name: %@", pictureName)
}
}
}
jsonData 包含两个子词典,一个没有键,一个有键“图片”。图片是一个包含一个子词典的数组。
关于json - 展开 Json Swift(发现为零),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30820019/
如何在代码中展开/折叠WPF扩展器?我需要这样做才能在其中初始化控件。 最佳答案 使用IsExpanded属性,将其设置为true以使内容可见: myExpander.IsExpanded = tru
Powershell 展开让我发疯。 我有以下代码可以从交换收件人处检索电子邮件地址。我使用 ArrayList 是因为当您希望能够从数组中删除项目时,很多人都建议使用它。 $aliases = Ne
是否可以展开/折叠数据表中的子表?我的子表包含与其上方行相关的信息,我想显示/隐藏图像的点击。只是想知道我会怎么做? 这是我目前使用的:
我正在尝试创建一个可扩展的文本区域,仅当该框为空时,该区域才会折叠回其原始高度。如果它不为空,那么我希望文本区域保持扩展并根据需要增长(即,当用户输入更多文本时增长)。文本区域永远不应该隐藏输入的文本
当尝试将 nestedSortable jQuery 插件与其网站上提供的示例一起使用时,该插件无法正常工作。 拖放可以工作,但是当我需要折叠/展开时就会出现问题。我使用了另一个问题中建议的解决方案,
我有一个显示嵌套数据的表。数据如下所示: Objective 1 Objective 1.1 Objective 1.1.1 Objective 1.2
我正在使用 jQuery 从屏幕左侧展开/缩回菜单栏。 这是我到目前为止所拥有的: $(document).ready(function(){ $('.menu-button').on("clic
如何根据类别向页面上的图像添加隐藏/显示(折叠/展开)功能? 我希望具有特定类的图像在加载时折叠,并在 JS 中定义一些任意标记(比方说, Show ),然后在扩展中具有不同的任意标记( Hide )
我需要在折叠和展开后触发事件调整大小。当我尝试使用 SWT.Collapse 和 SWT.Expand 执行此操作时,树上没有任何更改,因为它在发生之前就已触发。有什么办法吗? 最佳答案 尝试调用 D
我有一个如下所示的域: package object tryme { type ALL = AlarmMessage :+: PassMessage :+: HeyMessage :+: CNil
我有一个扩展器列表,我想用全局切换按钮控制其展开状态(IsExpanded),该按钮应该在展开/折叠状态之间切换。 到目前为止,我得到的解决方案是通过将扩展器的 IsExpanded 状态绑定(bin
我试图根据 QWidget 是否展开/折叠来自动调整其大小。我尝试了几种发布的方法here和 here . 我没有设法采用这些,以便它按照我想要的方式工作:我希望 QWidget 在展开时调整自身大小
我正在尝试显示对象模型(机器人)列表,这些模型有一个可以是另一个机器人的字段 Parent。 我已经使用 Django 的 MPTT 实现了一个嵌套列表: {% load mptt_tags %}
鉴于下表/代码,我想添加两项。我不太了解 JavaScript,这段代码是另一个程序员留下的。该代码在所有其他方面都按预期工作。 这是两个项目: 表格应该以折叠状态开始。所有节点都应该是崩溃到“祖 p
我想要一张可以展开或折叠的表格。我的要求是当我点击表格行然后隐藏行显示或者当我点击其他表格行然后上一个打开的行隐藏或显示相对隐藏行。我发现一个 jquery jxpand 非常适合我,它显示隐藏的行但
如果当您向下滚动页面时元素展开或折叠,页面会突然重置并且焦点会移动到页面顶部。 有什么方法可以防止页面移动或使其不那么突然? $(document).ready(function () {
我正在使用以下代码来扩展特定的线性布局,并且遵循了本教程 http://gmariotti.blogspot.sg/2013/09/expand-and-collapse-animation.html
当垂直偏移超过特定阈值时,如何使android中的可折叠工具栏自动折叠/展开? 例如,如果垂直偏移超过 getScrollRange() 的半点,则可折叠工具栏应自动展开,低于该阈值时应折叠。 最佳答
http://t-webdesign.co.uk/new/ 如何在不使用固定高度属性的情况下让灰色 div (#content_right) 扩展到与左侧 div 相同的大小? 谢谢 最佳答案 你可能
设置一个简单的 WordPress 博客,仅包含一个页面,即博客存档。但我遇到了一个问题,我想要切换摘录和内容显示更多/显示更少的功能,以便访问者可以轻松浏览同一页面上的帖子,而无需页面重新加载或被发
我是一名优秀的程序员,十分优秀!