问题标签 [jsondecoder]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
json - 无法从 JSON 获取字典
如何从 Json 中获取字典?
json - 可解码 JSONDecoder 处理相同值的不同编码键
我正在使用 Swift 可解码协议来解析我的 JSON 响应:
我遇到了一个问题,有时我会使用键“Id”而不是“ScanId”来获取 ScanId 值。有没有办法解决这个问题?
谢谢
json - 为什么#Codable# 在下面的代码中不起作用?
我有下面的代码来测试Codable
协议和JSONDecoder
.
我的问题是,为什么json4不能被解码?或者我如何解码json4?
php - 如何将数组中的所有项目与 laravel 相乘?
我在控制器中有这样的输出数组
我想将数组的每个元素相乘,例如这样
(美国 * 妻子教育 * 丈夫教育 * 孩子人数 * 妻子宗教 * 妻子现在工作 * 丈夫职业 * 生活指数 * 媒体曝光)
json - Processing JSON using Swift JSONDecoder
Here is my JSON I am trying to parse
I want to be able to filter out the layout types that are not supported. I am using the JSONDecoder to to convert the JSON data into structs but I am having an issue processing the rows. I am attempting to convert each row using let row = try? rowContainer.decode(Row.self) but I can figure out how to move to the next one if it fails unless I decode it to an empty struct. I tried just decoding it to a Dictionary but it won't except Any for the value field.
swift - 如何使 RealmSwift RealmOptional 与 Swift Codable 兼容?
我面临一个问题,我无法使 RealmOptional 与带有 json 解码器的 swift 新 Codable 功能兼容。
考虑以下 Realm 对象。
在这里,我们可以将类声明为 Codable,因为我在这个 gist的帮助下为 RealmOptinal 编写了一个扩展。但问题是当解码器解码 json 时。
考虑这个json
在这个 json 中,所有数据都被传递,并且这与代码完美解码。
但是,如果我numberOfStudents
从应该是 RealmOptional 对象的 json 数据中删除密钥,它将引发错误并且不会解码,因为 RealmOptional 不是 swift 可选的,因此解码器认为 json 数据中应该有一个密钥。如果JSONDecoder
json 中不存在密钥并且该属性被声明为可选,则它不会尝试解码。它只是跳到其他键。
到目前为止,我没有覆盖初始化程序,因为我们拥有RealmOptional
RealmLists
等的所有支持扩展。但是现在我必须覆盖init(from decoder: Decoder)
它才能手动解码它,并且 Realm 模型中有超过50 个属性(你知道我的意思)。
如果我们覆盖初始化器,我觉得使用没有意义,JSONDecoder
因为与使用 JSONDecoder 相比,手动工作更多。
所以有人可以建议我使 RealmOptional 兼容的替代解决方案,JSONDecoder
这样我们就不必覆盖初始化程序。
php - PHP:JSON_DECODE 不适用于以下数据
我正在尝试通过以下代码解码此 json 数据,但它不起作用。
ios - 在 SWIFT 4 中将 JSON 数据移出本地范围
所以,我一直试图让这段代码工作几天,但我不知道我做错了什么。
我从网上获取一个 JSON 并用 Struct 块解析它。
问题是:我想使用我创建 de decode 函数的 JSON 中的字典和数组。
这是代码
ios - 如何在 Swft 的结构模型类中为可选参数设置默认值?
我正在使用一个模型-
正在从服务器获取数据,服务器仅提供名称和距离。我添加了 isSelected 来跟踪被选中的项目。
我正在使用 JSDecoder 类来解析这些数据。
我尝试使用var isSelected : Bool ?? false
,但它给出了编译器错误。
由于服务器未提供 isSelected 值,有什么方法可以将默认值设置为 false 吗?