(reprint) Game Planner Excel config table to turn into JSON file (ii)

Source: Internet
Author: User

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
  1. function Tablefromfile (fileName)
  2. Local T
  3. Local jsonstring
  4. Local Path = Ccfileutils:sharedfileutils (): Fullpathforfilename (FileName)
  5. Local myfile = Io.open (Path,"R")
  6. if myfile = = Nil Then
  7. return Nil
  8. End
  9. jsonstring = Myfile:read ("*a")
  10. t = Self.cjson.decode (jsonstring)
  11. Serialise_value (t)
  12. --print (table.entities[1].entity. HP)
  13. Myfile.close ()
  14. return T
  15. End

For example, the JSON file is this:

[CPP]View Plaincopy
  1. {
  2. "Entities": [
  3. {
  4. "entity": {
  5. "Carryround": -1.0,
  6. "target": "",
  7. " additionvalue": "",
  8. " updatecondition": "",
  9. " reduction": "",
  10. " name": "Common object Attack",
  11. "Job": " ",
  12. "Gank": -1.0,
  13. " effect": "",
  14. "type": 2.0,
  15. "id": 0.0,
  16. " Round": "",
  17. "desc": " "
  18. }
  19. },
  20. ]
  21. }

It can be used like this after turning into a table

[CPP]View Plaincopy
    1. Local data = Tablefromfile ("Xxx.json")
    2. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.