0
파일 스트림을 통해 JSON 문서 "source.json"을 읽지 만 json 파일에서 데이터를 얻는 방법은 무엇입니까? 그런 다음 새로 편집 한 json 데이터를 동일한 파일에 다시 추가하려고합니다.Filestream 및 읽기에서 데이터 받기
Dim pathSource As String = "Server.MapPath('~/source.json')"
Try
Using fs As FileStream = New FileStream(pathSource, _
FileMode.Open, FileAccess.Read)
Dim bytes() As Byte = New Byte((fsSource.Length) - 1) {}
Dim numBytesToRead As Integer = CType(fsSource.Length,Integer)
Dim numBytesRead As Integer = 0
While (numBytesToRead > 0)
Dim n As Integer = fsSource.Read(bytes, numBytesRead, _
numBytesToRead)
If (n = 0) Then
Exit While
End If
numBytesRead = (numBytesRead + n)
numBytesToRead = (numBytesToRead - n)
End While
numBytesToRead = bytes.Length
Dim xmlBuilder = New StringBuilder()
fs.Seek(0, SeekOrigin.Begin)
Dim ms As New MemoryStream()
fs.CopyTo(ms)
xmlBuilder.Append(Encoding.UTF8.GetString(ms.ToArray()))
ms.Flush()
ms.Close()
'???How to access the data from the file "source.json" you just read in???
'Edit the file "source.json" data
?? How to put it into "bytesout" the edited data???
Using fsAppend As FileStream = New FileStream(pathSource, _
FileMode.Append, FileAccess.Write)
fsAppend.Write(bytesout, 0, numBytesToRead)
End Using
End Using
Catch ioEx As FileNotFoundException
Console.WriteLine(ioEx.Message)
End Try
저는 휠을 다시 발명하지 않고 json.net을 사용하지 마십시오. http://www.newtonsoft.com/json/ help/html/ReadJson.htm – mxmissile
NewtonSoft 패키지를 가져올 수 없다는 오류가 발생합니다. – losopha
그런 다음 ['JavaScriptSerializer'] (https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx) 또는 ['DataContractJsonSerializer'] (https : // msdn. microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx). JSON은 어떤 모습입니까? – dbc