jsonencoder

Array to string conversion while using canvas js in yii2

坚强是说给别人听的谎言 提交于 2020-04-30 09:17:38
问题 I am trying to load a chart on my index page in yii2 project . Below is my code <?PHP $dataPoints1 = array( array("label"=> "2010", "y"=> 36.12), array("label"=> "2011", "y"=> 34.87), array("label"=> "2012", "y"=> 40.30), array("label"=> "2013", "y"=> 35.30), array("label"=> "2014", "y"=> 39.50), array("label"=> "2015", "y"=> 50.82), array("label"=> "2016", "y"=> 74.70) ); $dataPoints2 = array( array("label"=> "2010", "y"=> 64.61), array("label"=> "2011", "y"=> 70.55), array("label"=> "2012",

JSONEncoder with multiple structures

[亡魂溺海] 提交于 2020-01-24 01:09:07
问题 Hi I have multiple JSON Packets like I wrote below. { "data" : { "lng" : 36.159999999999997, "lat" : 50.359999999999999, "accuracy" : 5 }, "header" : { "type" : "loc" } } and this one { "data" : { "time" : 15646565455, "tz" : "+2", "system" : 5 }, "header" : { "type" : "syn" } } I have structure for my packets and it worked for one structure of packets. But how to use it for multiple packets structures. struct Packet : Codable { enum StructureType : String, Codable { case location = "loc"

JSONEncoder's dateEncodingStrategy not working

随声附和 提交于 2019-12-20 02:59:08
问题 I am trying to serialize a struct to a String using Swift 4's Encodable+JSONEncoder. The object can hold heterogenous values like String, Array, Date, Int etc. The used approach works fine with the exception of Date. JSONEncoder's dateEncodingStrategy property is not having any effect. Here is a snippet which reproduces the behaviour in Playground: struct EncodableValue:Encodable { var value: Encodable init(_ value: Encodable) { self.value = value } func encode(to encoder: Encoder) throws {

Store Encodables in a Swift Dictionary

时光毁灭记忆、已成空白 提交于 2019-11-30 09:33:33
问题 I'm looking to store models objects in a Dictionary and would like to serialize the whole dictionary using JSONEncoder into data and subsequently into a string and save it. The idea is to use Swift 4's out of the box Encodable to ensure anything that I add to the dictionary will be serialized which can include primitives and custom objects (which will themselves conform to Encodable ). The Challenge is what type should I declare the dictionary to be: If I use [String: Any] , it won't know how