Flutter에서 JSON 파일을 구문 분석하는 동안 Null 오류

킬러 맨 2003

JSON 파일을 읽고 해당 콘텐츠를 표시하는 앱을 만들려고합니다.

JSON 파일은 다음과 같습니다.

    "Jett": {
        "name":
            "Jett",
        "info":
            "From Korea comes Jett, an agile fighter who prioritizes movement over everything. Her abilities include a teleportation-based dash and an updraft that lets her reach higher ledges. She also has a smokebomb ability to hinder sightlines and a powerful Bladestorm ultimate that deals moderate-to-heavy damage and remains accurate even while she's moving [1]. Jett is one of the few Agents with a passive ability. Holding the jump key while in the air will allow Jett to slow her descent. Jett's Ultimate allows her to wield several throwing knives that deal moderate damage and kill on headshots. Getting a kill replenishes your daggers and you can choose to throw them one at a time or throw all remaining daggers in a short-ranged burst.",
        "ability 1":{
            "name" : "Cloudburst",
            "type" : "Basic",
            "cost" : "100",
            "duration" : "7 Secs",
            "health" : "N/A",
            "description" : "Instantly throw a projectile that expands into a brief vision cloud on impact with a surface. Hold the ability key to curve the cloud in the direction of your crosshair."
        },

        "ability 2" : {
            "name" : "Updraft",
            "type" : "Basic",
            "cost" : "100",
            "duration" : "N/A",
            "health" :"N/A",
            "description" : "Instantly propel Jett high into the air."
        },

        "ability 3" : {
            "name" : "Tailwind",
            "type" : "Signature",
            "cost" : "None",
            "duration" : "N/A",
            "health" :"N/A",
            "description" : "Instantly propel in the direction she is moving. If Jett is standing still, she will propel forward."
        },
        
        "ability 4" : {
            "name" : "Bladestorm",
            "type" : "Ultimate",
            "cost" : "6 Ult Points",
            "duration" : "N/A",
            "health" :"N/A",
            "description" : "Equip a set of 5 highly accurate throwing knives. Fire to throw a single knife. Alternative Fire to throw all remaining daggers at once. Restocks upon killing an enemy."
        }
        

    },

    "Breach": {
        "name": "Breach",
        "info":
            "Breach fires powerful, targeted kinetic blasts to aggressively clear a path through enemy ground. The damage and disruption he inflicts ensures no fight is ever fair. Breach's main gimmick is the ability to use all of his abilities through the geometry of the map,whether it is through walls, roofs, or terrain. This ability set rewards experienced players for knowing the maps well. His abilities also seem to reward an aggressive playstyle despite most of his abilities being crowd-control based.",
        "ability 1":{
            "name" : "Aftershock",
            "type" : "Basic",
            "cost" : "100",
            "duration" : "N/A",
            "health" : "N/A",
            "description" : "Equip a fusion charge. Fire the charge to set a slow-acting burst through the wall. The burst does heavy damage to anyone caught in its area."
        },

        "ability 2" : {
            "name" : "Flashpoint",
            "type" : "Basic",
            "cost" : "200",
            "duration" : "2 Secs",
            "health" :"N/A",
            "description" : " Equip a blinding charge. Fire the charge to set a fast-acting burst through the wall. The charge detonates to blind all players looking at it."
        },

        "ability 3" : {
            "name" : "Fault Line",
            "type" : "Signature",
            "cost" : "None",
            "duration" : "N/A",
            "health" :"N/A",
            "description" : "Equip a seismic blast. Hold Fire to increase the distance. Release to set off the quake, dazing all players in its zone and in a line up to the zone."
        },
        
        "ability 4" : {
            "name" : "Rolling Thunder",
            "type" : "Ultimate",
            "cost" : "7 Ult Points",
            "duration" : "N/A",
            "health" :"N/A",
            "description" : "Equip a seismic charge. Fire to send a cascading quake through all terrain in a large cone. The quake dazes and knocks up anyone caught in it."
        }
        
}

클래스는 다음 코드를 사용하여 CharacterPageConstructor라는 다른 클래스로 전달되는 'characterName'이라는 문자열을 보유합니다.

onTap: () {
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => CharacterPageConstructor(characterName)));
      },

CharacterPageConstructor는이 characterName을 매개 변수로 사용하여 Json 파일에서 이름을 검색합니다. 내가 읽는 데 사용한 코드는 다음과 같습니다.

class CharacterPageConstructor extends StatelessWidget {
  final String characterName;
  CharacterPageConstructor(this.characterName);
  String jsonData;
  Future<String> _read() async {
    try {
      final File file = File('assets/data/character_data.json');
      jsonData = await file.readAsString();
    } catch (e) {
      print("Couldn't read file");
    }
    return jsonData;
  }

  Widget build(BuildContext context) {
    Map<String, dynamic> characterData = jsonDecode(jsonData);
    var name = characterData[characterName]['name'];
    var info = characterData[characterName]['info'];
    return Scaffold(
      backgroundColor: Color.fromARGB(255, 15, 23, 34),
      body: Container(
              margin: EdgeInsets.all(20),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(5.0),
                color: Color.fromARGB(175, 252, 70, 82),
              ),
              child: Row(
                children: [ Text(name),
                            Text(info)                       

그러나 결국 다음 오류가 발생합니다.

The following NoSuchMethodError was thrown building CharacterPageConstructor(dirty):
The getter 'length' was called on null.
Receiver: null
Tried calling: length

The relevant error-causing widget was
CharacterPageConstructor
lib\characterBox.dart:40

When the exception was thrown, this was the stack
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      _parseJson (dart:convert-patch/convert_patch.dart:39:28)
#2      JsonDecoder.convert (dart:convert/json.dart:505:36)
#3      JsonCodec.decode (dart:convert/json.dart:156:41)
#4      jsonDecode (dart:convert/json.dart:96:10)
...

오류 lib\characterBox.dart:40는 다음 줄을 나타냅니다.

builder: (context) => CharacterPageConstructor(characterName)));
Vinay HP
final File file = File('assets/data/character_data.json');

jsonData = await file.readAsString();

로 변경:

String data = await rootBundle.loadString('assets/data/character_data.json');

jsonData = json.decode(data);

print(jsonData);

또는

final file = File('assets/data/character_data.json');

String data = await file.readAsString();

jsonData = json.decode(data);

print(jsonData);

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Python에서 json을 구문 분석하는 동안 오류 메시지

분류에서Dev

xml 파일을 구문 분석하는 동안 Null 지점 오류

분류에서Dev

자바 스크립트에서 Json을 구문 분석하는 동안 오류가 발생했습니다.

분류에서Dev

Amazon Athena에서 중첩 된 JSON을 구문 분석하는 동안 내부 오류 발생

분류에서Dev

Python에서 JSON을 구문 분석하는 동안 오류가 발생했습니다.

분류에서Dev

페이로드에 null 값이없는 동안 JSON 구문 분석에서 nil 오류가 발생합니다.

분류에서Dev

객체가있는 JSON 파일을 구문 분석하는 동안 오류가 발생했습니다.

분류에서Dev

Swift에서 JSON을 구문 분석하는 동안 nil

분류에서Dev

Angular에서 ngTemplateOutlet을 사용하는 동안 템플릿 구문 분석 오류

분류에서Dev

Android에서 json 데이터를 구문 분석하는 동안 null 값을 가져옵니다.

분류에서Dev

geotools 파서로 xml을 구문 분석하는 동안 null을 얻는 방법

분류에서Dev

where 절에서 json_extract_path_text () 함수를 사용하는 동안 JSON 구문 분석 오류

분류에서Dev

컴파일 오류를 구문 분석하는 동안 파일 끝에 도달했습니다.

분류에서Dev

자산 폴더에서 Json 파일을 구문 분석하는 동안 NullPointerException이 발생했습니다.

분류에서Dev

Python을 사용하여 특정 값을 인쇄하는 동안 JSON 파일 구문 분석 오류 (json.decoder.JSONDecodeError : Extra data : line 2 column 1 (char 20))

분류에서Dev

npm 오류! '... ob ":"^ 7.0.0 ","istanbu'근처에서 구문 분석하는 동안 예상치 못한 JSON 입력 종료

분류에서Dev

json에서 객체로 날짜를 구문 분석하는 동안 오류가 발생했습니다.

분류에서Dev

문자열이 변경 될 때 JSON을 구문 분석하는 동안 Python 오류

분류에서Dev

Java에서 JSON 문자열을 JSONObject로 구문 분석하는 중 오류

분류에서Dev

ISBN을 사용하는 동안 SAX 구문 분석 오류

분류에서Dev

Babel / browserify에서 "JSON을 구문 분석하는 동안 오류-예기치 않은 토큰 o"가 발생합니다.

분류에서Dev

URL에서 json을 구문 분석하는 동안 시간 초과 메시지

분류에서Dev

Ajax를 사용하여 JSON 값을 구문 분석하는 동안 오류가 발생했습니다.

분류에서Dev

C #에서 날짜 문자열을 구문 분석하는 동안 오류가 발생했습니다.

분류에서Dev

json 구문 분석 후 null을 반환하는 flutter 모델

분류에서Dev

서블릿에서 json 객체를 구문 분석하는 동안 null 값이 발생하는 이유

분류에서Dev

json을 R로 구문 분석하는 동안 오류가 발생했습니다.

분류에서Dev

simle json 파서를 사용하는 Java의 JSON 구문 분석 오류

분류에서Dev

Julia에서 데이터를 스트리밍하는 동안 텍스트 파일에서 마지막 위치 값을 구문 분석 할 때 오류 발생

Related 관련 기사

  1. 1

    Python에서 json을 구문 분석하는 동안 오류 메시지

  2. 2

    xml 파일을 구문 분석하는 동안 Null 지점 오류

  3. 3

    자바 스크립트에서 Json을 구문 분석하는 동안 오류가 발생했습니다.

  4. 4

    Amazon Athena에서 중첩 된 JSON을 구문 분석하는 동안 내부 오류 발생

  5. 5

    Python에서 JSON을 구문 분석하는 동안 오류가 발생했습니다.

  6. 6

    페이로드에 null 값이없는 동안 JSON 구문 분석에서 nil 오류가 발생합니다.

  7. 7

    객체가있는 JSON 파일을 구문 분석하는 동안 오류가 발생했습니다.

  8. 8

    Swift에서 JSON을 구문 분석하는 동안 nil

  9. 9

    Angular에서 ngTemplateOutlet을 사용하는 동안 템플릿 구문 분석 오류

  10. 10

    Android에서 json 데이터를 구문 분석하는 동안 null 값을 가져옵니다.

  11. 11

    geotools 파서로 xml을 구문 분석하는 동안 null을 얻는 방법

  12. 12

    where 절에서 json_extract_path_text () 함수를 사용하는 동안 JSON 구문 분석 오류

  13. 13

    컴파일 오류를 구문 분석하는 동안 파일 끝에 도달했습니다.

  14. 14

    자산 폴더에서 Json 파일을 구문 분석하는 동안 NullPointerException이 발생했습니다.

  15. 15

    Python을 사용하여 특정 값을 인쇄하는 동안 JSON 파일 구문 분석 오류 (json.decoder.JSONDecodeError : Extra data : line 2 column 1 (char 20))

  16. 16

    npm 오류! '... ob ":"^ 7.0.0 ","istanbu'근처에서 구문 분석하는 동안 예상치 못한 JSON 입력 종료

  17. 17

    json에서 객체로 날짜를 구문 분석하는 동안 오류가 발생했습니다.

  18. 18

    문자열이 변경 될 때 JSON을 구문 분석하는 동안 Python 오류

  19. 19

    Java에서 JSON 문자열을 JSONObject로 구문 분석하는 중 오류

  20. 20

    ISBN을 사용하는 동안 SAX 구문 분석 오류

  21. 21

    Babel / browserify에서 "JSON을 구문 분석하는 동안 오류-예기치 않은 토큰 o"가 발생합니다.

  22. 22

    URL에서 json을 구문 분석하는 동안 시간 초과 메시지

  23. 23

    Ajax를 사용하여 JSON 값을 구문 분석하는 동안 오류가 발생했습니다.

  24. 24

    C #에서 날짜 문자열을 구문 분석하는 동안 오류가 발생했습니다.

  25. 25

    json 구문 분석 후 null을 반환하는 flutter 모델

  26. 26

    서블릿에서 json 객체를 구문 분석하는 동안 null 값이 발생하는 이유

  27. 27

    json을 R로 구문 분석하는 동안 오류가 발생했습니다.

  28. 28

    simle json 파서를 사용하는 Java의 JSON 구문 분석 오류

  29. 29

    Julia에서 데이터를 스트리밍하는 동안 텍스트 파일에서 마지막 위치 값을 구문 분석 할 때 오류 발생

뜨겁다태그

보관