Using the Python tool, the JSON file generated by Excel can be used in many languages, such as Objective-c, C++,lua,javascript and so on, to configure the data for the game level.
If the Lua language is selected, this JSON file cannot be used directly. Because the JSON file is just a JSON-formatted string, it needs to be converted into LUA's data format: table.
To convert the JSON file to table, you need to take advantage of the third-party class library Cjson, with the following code:
[CPP]View Plaincopy
- function Tablefromfile (fileName)
- Local T
- Local jsonstring
- Local Path = Ccfileutils:sharedfileutils (): Fullpathforfilename (FileName)
- Local myfile = Io.open (Path,"R")
- if myfile = = Nil Then
- return Nil
- End
- jsonstring = Myfile:read ("*a")
- t = Self.cjson.decode (jsonstring)
- Serialise_value (t)
- --print (table.entities[1].entity. HP)
- Myfile.close ()
- return T
- End
For example, the JSON file is this:
[CPP]View Plaincopy
- {
- "Entities": [
- {
- "entity": {
- "Carryround": -1.0,
- "target": "",
- " additionvalue": "",
- " updatecondition": "",
- " reduction": "",
- " name": "Common object Attack",
- "Job": " ",
- "Gank": -1.0,
- " effect": "",
- "type": 2.0,
- "id": 0.0,
- " Round": "",
- "desc": " "
- }
- },
- ]
- }
It can be used like this after turning into a table
[CPP]View Plaincopy
- Local data = Tablefromfile ("Xxx.json")
- Print (Data.entities[1].entity.name)
Original address: http://blog.csdn.net/zhuangyou123/article/details/10069391
(reprint) Game Planner Excel config table to turn into JSON file (ii)