初始json.感觉很方便啊。

var serverJSON:String = '{ "programmers": [{ "firstName": "Brett", "lastName":"McLaughlin", "email": "[email protected]" },{ "firstName": "Jason", "lastName":"Hunter", "email": "[email protected]" }, { "firstName": "Elliotte", "lastName":"Harold", "email": "[email protected]" }],"authors": [{ "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },{ "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },{ "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }],"musicians": [{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },{ "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }]}'

 

   var s:Object = JSON.decode(serverJSON);////编码
   //开始使用
  
   trace(s.programmers[0].firstName);//输出:Brett

   
   var myObject:Object = { name:"yesman", age:28 };
   var str:String = JSON.encode(myObject);/////解码
   trace(str);

你可能感兴趣的:(json)