我正在尝试将一个JSON发送到websocket。所需的格式是逗号,而当我将项目添加到字典时,它会创建一个分号。
必填格式:
{"key":"driver_location_updates","driverID":40,"coordinates":[25.22632,55.2844576]}
我创建的格式:
"driver_location_updates" =
{
coordinates = ( "24.96046731716484","67.05977029173361");
driverID = 16;
key = "driver_location_updates";
};
}
答案 0 :(得分:1)
正如您在评论中所说的那样
答案 1 :(得分:0)
我应该使用function _get_datatables_query()
{
$this->db->from($this->table);
$this->db->group_start();
foreach($this->column_search as $item)
{
if(strtoupper($_POST['search']['value'])) // if datatable send POST for search
{
$this->db->or_like($item, strtoupper($_POST['search']['value']));
}
}
$this->db->group_end();
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
将字典转换为json。
JSONSerialization
我希望您知道如何将答案转换为let dictionary: [String: Any] = ["key":"driver_location_updates", "driverID": 40, "coordinates": [25.22632,55.2844576]]
let jsonData = try? JSONSerialization.data(withJSONObject: dictionary, options: [])
let jsonString = String(data: jsonData!, encoding: .utf8)
print(jsonString)
答案 2 :(得分:0)
从格式上我猜你已经使用了[NSString stringWithFormat:@"%@"]
或得到了#34; JSON"致电-[NSDictionary description]
。
这不会创建JSON,而是数据结构的一般人类可读符号。它看起来像JSON,多年前我遇到了完全相同的问题:)
使用NSJSONSerialization
获取真正的JSON:
NSData *JSONData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 &error];
或直接写入流
[NSJSONSerialization writeJSONObject:dictionary toStream:writeStream options:0 error:&error]