cocos2dx json資料解析

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   os   io   strong   

轉自:http://blog.csdn.net/wangbin_jxust/article/details/9707873

cocos2dx本身沒有json解析類庫,我們這裡引入libjson進行解析。:http://sourceforge.net/projects/libjson/files/

我目前使用的版本是7.6.1。

1.下載libjson並解壓下載後,解壓出來,這裡對我們有用的檔案是:libjson.h;JSONOptions.h;_internal->Source檔案夾下的所有檔案;_internal->Dependencies檔案夾下的所有檔案。將這些檔案和檔案夾複製出來,放到項目中的classes目錄下,注意:檔案層次不能改變。2.添加源碼到項目為了項目結構更加清晰,這裡為json源碼建立一個檔案夾。‘然後將libjson裡的頭文化和cpp檔案添加進來。是我添加後的檔案;3.進行Json解析先在代碼中引入libjson:
#include "libjson.h"

然後就可以寫Json解析類了。如果不太會,可以參考下載的libjson檔案夾下->Getting Started->C++ Interface中的文檔。

JSONNode n(JSON_NODE);n.push_back(JSONNode("RootA", "Value in parent node"));JSONNode c(JSON_NODE);c.set_name("ChildNode");c.push_back(JSONNode("ChildA", "String Value"));c.push_back(JSONNode("ChildB", 42));n.push_back(c);std::string jc = n.write_formatted();std::cout << jc << std::endl;

OK,然後運行並查看輸出。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.