SwiftyJSON对象返回字符串

编程入门 行业动态 更新时间:2024-10-22 21:31:36
本文介绍了SwiftyJSON对象返回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用SwiftyJSON库将JSON解析为swift对象。我可以创建JSON对象并读取和写入它

I'm using the SwiftyJSON library to parse JSON into swift objects. I can create the JSON object and read and write to it

// Create json object to represent library var libraryObject = JSON(["name":"mylibrary","tasks":["Task1","Task2","Task3"]]) // Get println(libraryObject["name"]) println(libraryObject["tasks"][0]) // Set println("Setting first task to 'New Task'") libraryObject["tasks"][0] = "New Task" // Get println(libraryObject["tasks"][0]) // Convert object to JSON and print println(libraryObject)

所有这些都按预期工作。我只想将libraryObject转换回JSON格式的字符串!

All of this works as expected. I just want to convert the libraryObject back to a string in JSON format!

println(libraryObject)命令将我想要的内容输出到控制台但我找不到把它作为一个字符串的方式。

The println(libraryObject) command outputs what I want to the console but I can't find a way to get it as a string.

libraryObject.Stringvalue和libraryObject.String都返回空值但是当我尝试例如println(content:+ libraryObject)时,我在尝试追加String时遇到错误一个JSON

libraryObject.Stringvalue and libraryObject.String both return empty values but when I try eg println("content: "+libraryObject) I get an error trying to append a String to a JSON

推荐答案

来自SwiftyJSON的README 在GitHub上:

From the README of SwiftyJSON on GitHub:

//convert the JSON to a raw String if let string = libraryObject.rawString() { //Do something you want print(string) }

更多推荐

SwiftyJSON对象返回字符串

本文发布于:2023-11-26 18:25:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634683.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   对象   SwiftyJSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!