开发者

Create a text file via JSON

I'm using Flex 4 for building the communication to Arduino. There are three (3) main values coming from it (X,Y,Z). Here the Flex's code

newText.text = magnetic.readUTFBytes(magnetic.bytesAvailable);
d = JSON.decode(newText.text);
MNx = d["x"];
MNy = d["y"];
MNz = d["z"];

Is there any example or codes (in Flex) that can I create and save these values as开发者_JAVA百科 a TXT file (data.txt). These values as a structure should be like below.

    [
        {
            "time":"1",
            "x":"400",
            "y":"5",
            "z":"-6"

        },

        {
            " time ":"2",
            "x":"4",
            "y":"-40",
            "z":"700"
        },

    .
    .
    .

        {
            "time":"n",
            "x":"xn",
            "y":"yn",
            "z":"zn"
        }
    ]


You can directly serialize a JSON object and print it to the console or to a file.

  trace(JSON.encode(object));

or

  var string:String = JSON.encode(object).toString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜