Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

dart - How Can I Create an Object in Flutter

I have an object in javascript code like this. I need to do this object in flutter. How can I do same thing in flutter with below javascript code ?

var object = {
       tsSubCmds: [
             {
              entityType: "DEVICE",
              entityId: entityId,
              scope: "LATEST_TELEMETRY",
              cmdId: 10
              }
          ],
           historyCmds: [],
           attrSubCmds: [],
           entityDataCmds: []
};
var data = JSON.stringify(object);

I tried to do like this. but it did not work like this.

var data = '{ tsSubCmds: [{entityType: DEVICE, entityId: ' + dashboardId + ', scope: LATEST_TELEMETRY, cmdId: 10 }], historyCmds: [], attrSubCmds: [], entityDataCmds: []}';
data = jsonDecode(data);
var object = jsonEncode(data);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
var object = {
  'tsSubCmds': [
    {'entityType': "DEVICE", 'entityId': entityId, 'scope': 'LATEST_TELEMETRY', 'cmdId': 10}
  ],
  'historyCmds': [],
  'attrSubCmds': [],
  'entityDataCmds': []
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...