In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to create and use JSON data through LitJson in Unity". In daily operation, I believe many people have doubts about how to create and use JSON data through LitJson in Unity. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to create and use JSON data through LitJson in Unity". Next, please follow the editor to study!
Method 1: implement through getJSON
GetJSON is a method provided by jquery to read files in json format.
First, we introduce jquery into html, which can be introduced through Baidu CDN. The code is as follows:
You can then use the getJSON,getJSON code in script in the following format:
$.getJSON ("userinfo.json", function (data) {
/ / data represents the data in the read json
})
Reference example:
Step 1: create a file in json format named userinfo.json
[
{
"name": "Zhang San"
"sex": "male"
}
{
"name": "Li Si"
"sex": "male"
}
{
"name": "Wang Wu"
"sex": "female"
}
]
The second step is to create a html file (under the same json path) and name it index.html
Use jquery to read json format files
/ / listen for button click events
$("# btn") .click (function () {
/ / use getJSON to read data in userinfo.json files
$.getJSON ("userinfo.json", function (data) {
Console.log (data)
/ / obtain the div of jsonTip
Var $jsontip=$ ("# jsonTip")
/ / variables that store data
Var strHtml= "123"
/ / clear the content
$jsontip.empty ()
/ / traverse the acquired json format data into div
$.each (data, function (infoIndex, info) {
StrHtml + = "name:" + info ["name"] + "
"
StrHtml + = "gender:" + info ["sex"] + "
"
StrHtml + = "
"
})
/ / display the processed data
$jsontip.html (strHtml)
})
})
Method 2: use native js to implement
Refer to the sample code:
Use the json file created above
Modify the html file
Use jquery to read json format files
/ / listen for button click events
$("# btn") .click (function () {
/ / json file path under the same folder
Var url= "userinfo.json"
/ / declare a XMLHttpRequest
Var request=new XMLHttpRequest ()
/ / set the request method and path
Request.open ("get", url)
/ / do not send data to the server
Request.send (null)
/ / the XHR object gets the return information and executes
Request.onload=function () {
/ / the returned status is 200, which means the data has been obtained successfully
At this point, the study on "how to create and use JSON data through LitJson in Unity" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.