Imports System.Net
Imports System.IO
Imports Newtonsoft.Json.Linq
Partial Class Default15123
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim request As HttpWebRequest
Dim reader As StreamReader
Dim url As String = "https://api.mju.ac.th/Person/API/PERSON948......2020" 'ขอ Token Key จากผู้พัฒนาระบบ API อาจารย์ดร.สุระพล ริยะนา
Try
request = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New StreamReader(response.GetResponseStream())
Dim JSONresponseFromServer As String = reader.ReadToEnd()
Dim jResults As JArray = JArray.Parse(JSONresponseFromServer)
'#1
Dim results As List(Of JToken) = jResults.Children().ToList() 'JValue
Dim result1 = results.Where(Function(s) s("firstName") = "ณัฐกฤตา")
Dim result2 = From s In results
Where s("firstName") = "ณัฐกฤตา"
Select s
Dim demo1 As String = ""
Dim fName As String = ""
Dim lName As String = ""
For Each person As JObject In result1
For Each prop As JProperty In person.Properties()
Select Case prop.Name
Case "firstName" : fName = prop.Value
Case "lastName" : lName = prop.Value
End Select
Next
Next
Label1.Text = fName + " " + lName
'display. ณัฐกฤตา โกมลนาค
'#2
Dim p As New PersonPublic()
For Each person As JObject In result2
For Each prop As JProperty In person.Properties()
Select Case prop.Name
Case "firstName" : p.FirstName = prop.Value
Case "lastName" : p.LastName = prop.Value
End Select
Next
Next
Label2.Text = p.FirstName + " " + p.LastName
'display. ณัฐกฤตา โกมลนาค
Catch ex As Exception
ex.ToString()
End Try
End If
End Sub
End Class
c#.net ใช้ API + citizenID
public String getAPIByIDcard(String IDcard, String fieldName)
{
String url = string.Concat("https://api.mju.ac.th/Person/API/PERSON948....2020/", IDcard);
'ขอ Token Key จากผู้พัฒนาระบบ API อาจารย์ดร.สุระพล ริยะนา
String str = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
String JSONresponseFromServer = reader.ReadToEnd();
JArray jResults = JArray.Parse(JSONresponseFromServer);
List<JToken> results = jResults.Children().ToList();
foreach (JObject person in results)
{
foreach (JProperty prop in person.Properties())
{
if (prop.Name == fieldName)
{
str = prop.Value.ToString ();
}
}
}
return str;
}
catch
{
return "";
}
finally
{
}
}