当我尝试将文本写入文件时,我收到错误消息“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
我找不到错误实际来自哪里...... 文本也需要格式化,带引号和不带。谢谢你的帮助。
答案 0 :(得分:0)
假设VB Net ..你最好改变这个
Writer.Write("{" & vbNewLine & _
" champion : " & SelectChampion.Text & "," & vbNewLine & _
" title : " & TitleBox.Text & "," & vbNewLine & _
" type : " ........
...... etc