SwiftyJson是否可以迭代对象而不是数组?

时间:2016-02-20 18:58:24

标签: swift swifty-json

我有对象

 {"FIELD NAME":{
         "SUBNAME":{
            "FIELD_ONE":"DATA",
            "FIELD_TWO":"DATA",
          }
          "SUBNAME2":{
            "FIELD_THREE":"DATA",
            "FIELD_FOUR":"DATA",
          }
 }

我想从SUBNAME和SUBNAME2获取数据。问题是我不知道这些字段的名称以及它们中有多少字段。

是否可以使用SwiftJSON迭代它们?

1 个答案:

答案 0 :(得分:1)

将JSON转换为对象后,您可以执行以下操作: io.on("connection", function(socket){ //other methods where emit works socket.on("login", function(data) { try { pg.connect(conString, function(err, con) { var query = con.query("SELECT * FROM accounts WHERE username" + "='" + data.usn + "';"); query.on("row", function(row, result) result.addRow(row); }); query.on("end", function(result) { if (sha512(data.pwd, result.rows[0].salt).hash === result.rows[0].password) { socket.emit("loginResponse", { status: "Success" }); console.log("I GOT UP TO HERE WITHOUT EMITTING! WTF?"); console.log(sha512(data.pwd,result.rows[0].salt).hash); console.log(result.rows[0].password); } }); }); } catch (ex) { console.log(ex); } }); });