 |
|
ขอคำแนะนำหน่อยครับจะเขียนโปรแกรม ดึงค่าจากไฟล์ JSON มาโชว์ใน ListView ครับ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Public Class myName
Public Property Name() As String
Get
Return m_Name
End Get
Set(value As String)
m_Name = value
End Set
End Property
Private m_Name As String
Public Property Surname() As String
Get
Return m_Surname
End Get
Set(value As String)
m_Surname = value
End Set
End Property
Private m_Surname As String
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strJSON As String = Nothing
' JSON = [{"Name":"Weerachai","Surname":"Nukitram"},{"Name":"Adisorn","Surname":"Bunsong"}]
strJSON = " [{""Name"":""Weerachai"",""Surname"":""Nukitram""}, {""Name"":""Adisorn"",""Surname"":""Bunsong""}]"
Dim ms As New MemoryStream(Encoding.UTF8.GetBytes(strJSON))
Dim list As New ObservableCollection(Of myName)
Dim serializer As New DataContractJsonSerializer(GetType(ObservableCollection(Of myName)))
list = DirectCast(serializer.ReadObject(ms), ObservableCollection(Of myName))
For Each name As myName In list
Console.WriteLine("Name : " & name.Name.ToString())
Console.WriteLine("Surname : " & name.Surname.ToString())
Console.WriteLine("======================")
Next
End Sub
มันเป็น List(T) เอาไปยัดลง DataSource ของ ListView ได้เลยครับ
VB.NET/C# Create JSON (DataContractJsonSerializer .
|
 |
 |
 |
 |
Date :
2015-11-09 16:36:19 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Dim url As String = "https://www.thaicreate.com/json.php"
Dim json = New WebClient().DownloadString(url)
|
 |
 |
 |
 |
Date :
2015-11-09 18:14:28 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|