如何从Unity更新JSON文件并将其发送回服务器 [英] How to update a JSON file from Unity and send it back to the server
问题描述
我是一名游戏开发人员,但是我刚开始使用JSON进行网络开发.但是,我正在尝试学习如何通过将存储在我的Web主机服务器上的JSON文件与Unity项目一起使用来实现在线高分系统.到目前为止,我可以通过使用Unity中的WWW类从远程JSON文件中获取用户名及其分数.但是,我不确定将现有的/添加新的数据对更新到JSON文件中的最佳方法是什么.我已经在网上寻找合适的文档/教程已有好几个小时了,但是我没有找到适合自己的文档/教程.任何人都可以从客户端(Unity)和服务器端提供一些这样做的提示和建议吗?预先感谢!
I am a game developer, but I am new to web development with JSON. However, I am trying to learn how to implements an online high score system by using a JSON file stored on my web host server with a Unity project. So far, I can get user names and their scores from the remote JSON file by using the WWW class in Unity. However, I am not sure what would be the best way to update existing /add new pairs of data to the JSON file. I have been seeking for proper documents/tutorials online for hours, but I didn't find one that works for me. Can anyone please provides some hints and suggestions for doing this from both client side(Unity) and server side? Thanks in advance!
推荐答案
检查库下方的链接以进行JSON操作
Check on the link below the library for JSON manipulation
http://wiki.unity3d.com/index.php/SimpleJSON
SimpleJSON是易于使用的JSON解析器和构建器.
SimpleJSON is an easy to use JSON parser and builder.
http://wiki.unity3d.com/index.php?title=JSONObject
JSONObject: 将JSON格式的字符串解码为可用的数据结构, 将结构化数据编码为JSON格式的字符串, 可与Dictionary和WWWForm互操作
JSONObject : Decode JSON-formatted strings into a usable data structure, Encode structured data into a JSON-formatted string, Interoperable with Dictionary and WWWForm
两个库都允许您编辑现有值并将新值添加到原始JSON
Both libraries allows you to edit existing values and add new ones to your original JSON
要将JSON发送回服务器,可以使用WWWForm: http://docs.unity3d .com/ScriptReference/WWWForm.html
To send your JSON back to the server you can use WWWForm : http://docs.unity3d.com/ScriptReference/WWWForm.html
这篇关于如何从Unity更新JSON文件并将其发送回服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!