例子2:json
import 'dart:convert'; void main() { String asdf = '{"game":"bi_da_xiao","lev_N":{"rooms":"1","room":[{"num":"1","tables":{"1":"Y","2":"Y"}}]},"lev_M":{"rooms":"2","room":[{"num":"1","tables":{"1":"Y","2":"Y"}},{"num":"2","tables":{"1":"Y","2":"Y"}}]},"lev_H":{"rooms":"3","room":[{"num":"1","tables":{"1":"Y","2":"Y"}},{"num":"2","tables":{"1":"Y","2":"Y"}},{"num":"3","tables":{"1":"Y","2":"Y"}}]}}'; print(json.decode(asdf)); print(json.decode(asdf).runtimeType); print(json.decode(asdf)["lev_M"]); print(json.decode(asdf)["lev_M"].runtimeType); print(json.decode(asdf)["lev_M"]["rooms"]); print(json.decode(asdf)["lev_M"]["rooms"].runtimeType); print(json.decode(asdf)["lev_M"]["room"]); print(json.decode(asdf)["lev_M"]["room"].runtimeType); print(json.decode(asdf)["lev_M"]["room"][0]); print(json.decode(asdf)["lev_M"]["room"][0].runtimeType); print(json.decode(asdf)["lev_M"]["room"][0]["num"]); print(json.decode(asdf)["lev_M"]["room"][0]["tables"]); print(json.decode(asdf)["lev_M"]["room"][0]["tables"]["1"]); }
輸出:spa
{game: bi_da_xiao, lev_N: {rooms: 1, room: [{num: 1, tables: {1: Y, 2: Y}}]}, lev_M: {rooms: 2, room: [{num: 1, tables: {1: Y, 2: Y}}, {num: 2, tables: {1: Y, 2: Y}}]}, lev_H: {rooms: 3, room: [{num: 1, tables: {1: Y, 2: Y}}, {num: 2, tables: {1: Y, 2: Y}}, {num: 3, tables: {1: Y, 2: Y}}]}} _InternalLinkedHashMap<String, dynamic> {rooms: 2, room: [{num: 1, tables: {1: Y, 2: Y}}, {num: 2, tables: {1: Y, 2: Y}}]} _InternalLinkedHashMap<String, dynamic> 2 String [{num: 1, tables: {1: Y, 2: Y}}, {num: 2, tables: {1: Y, 2: Y}}] List {num: 1, tables: {1: Y, 2: Y}} _InternalLinkedHashMap<String, dynamic> 1 {1: Y, 2: Y} Y Process finished with exit code 0