-1

当我尝试将文本写入文件时,我收到一条错误消息,提示“FormatException 未处理”

这是代码:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim ChampPath As String = FolderBrowserDialog1.SelectedPath & "\League of Legends\Config\Champions"
    Dim NamePath As String = ChampPath & "\" & SelectChampion.Text
    Dim FilePath As String = NamePath & "\" & SelectChampion.Text & ".json"
    Dim Map As String
    Dim Mode As String
    System.IO.Directory.CreateDirectory(NamePath)
    System.IO.File.Create(FilePath).Dispose()
    If (SelectMap.Text = "Any") Then
        Map = "any"
    ElseIf (SelectMap.Text = "Summoners Rift") Then
        Map = "1"
    ElseIf (SelectMap.Text = "Twisted Treeline") Then
        Map = "10"
    ElseIf (SelectMap.Text = "Crystal Scar") Then
        Map = "8"
    ElseIf (SelectMap.Text = "Proving Grounds") Then
        Map = "3"
    End If
    If (SelectMode.Text = "Any") Then
        Mode = "any"
    ElseIf (SelectMode.Text = "Classic") Then
        Mode = "CLASSIC"
    ElseIf (SelectMode.Text = "Dominon") Then
        Mode = "ODIN"
    ElseIf (SelectMode.Text = "Proving Grounds") Then
        Mode = "ARAM"
    End If
    If (System.IO.File.Exists(FilePath)) Then
        Using Writer As StreamWriter = New StreamWriter(FilePath)
            Writer.Write("{" & vbNewLine &
" ""champion"":""" & SelectChampion.Text & """," & vbNewLine &
"   ""title"":""" & TitleBox.Text & "", " " & vbNewLine &
"   ""type"":""" & TypeBox.Text & "", " " & vbNewLine &
"   ""map"":""" & Map & "", " " & vbNewLine &
"   ""mode"":""" & Mode & "", " " & vbNewLine &
"   ""priority""" & SelectPriority.Text & "", " " & vbNewLine &
"   ""blocks"":[ " & vbNewLine &
  "{" & vbNewLine &
"         ""type"":""starting"", " & vbNewLine &
"         ""items"":[ " & vbNewLine &
     "{" & vbNewLine &
"               ""id"":""1001"", " & vbNewLine &
"               ""count"":1 " & vbNewLine &
       "}," & vbNewLine &
        "{" & vbNewLine &
"               ""id"":""3010"", " & vbNewLine &
"               ""count"":3 " & vbNewLine &
        "}" & vbNewLine &
     "]" & vbNewLine &
  "}," & vbNewLine &
  "{" & vbNewLine &
"         ""type"":""essential"", " & vbNewLine &
"         ""items"":[ " & vbNewLine &
        "{" & vbNewLine &
"               ""id"":""3001"", " & vbNewLine &
"               ""count"":1 " & vbNewLine &
        "}," & vbNewLine &
        "{" & vbNewLine &
"               ""id"":""3089"", " & vbNewLine &
"               ""count"":1 " & vbNewLine &
        "}" & vbNewLine &
     "]" & vbNewLine &
  "}," & vbNewLine &
  "{" & vbNewLine &
"         ""type"":""offensive"", " & vbNewLine &
"         ""items"":[ " & vbNewLine &
        "{" & vbNewLine &
"               ""id"":""3100"", " & vbNewLine &
"               ""count"":1 " & vbNewLine &
        "}," & vbNewLine &
        "{" & vbNewLine &
"               ""id"":""3128"", " & vbNewLine &
"               ""count"":1 " & vbNewLine &
       "}," & vbNewLine &
       "{" & vbNewLine &
"               ""id"":""3135"", " & vbNewLine &
"               ""count"":1 " & vbNewLine &
        "}" & vbNewLine &
     "]" & vbNewLine &
  "}," & vbNewLine &
  "{" & vbNewLine &
"         ""type"":""defensive"", " & vbNewLine &
"         ""items"":[ " & vbNewLine &
        "{" & vbNewLine &
"               ""id"":""3140"", " & vbNewLine &
"               ""count"":1 " & vbNewLine &
        "}," & vbNewLine &
        "{" & vbNewLine &
"               ""id"":""3157"", " & vbNewLine &
"               ""count"":1 " & vbNewLine &
        "}" & vbNewLine &
     "]" & vbNewLine &
  "}" & vbNewLine &
"]" & vbNewLine &
"}")
        End Using
    End If
End Sub

我找不到错误的实际来源......文本也需要按原样格式化,包括引号和其他内容。谢谢你的帮助。

4

1 回答 1

0

假设VB Net ..最好你这样改变

Writer.Write("{" & vbNewLine & _
" champion  : " & SelectChampion.Text & "," & vbNewLine & _
" title     : " & TitleBox.Text & "," & vbNewLine & _
" type      : "  ........
...... etc
于 2013-04-29T09:28:53.590 回答