What's new

Closed Json file Extraction

Status
Not open for further replies.

tamadsijuan

Eternal Poster
Joined
Feb 17, 2016
Posts
849
Reaction
327
Points
260
Mga master pa help naman po masolve ung problem ko

Ex. Json File

{
"ID": 21,
"container": "a",
"created_entity_ids": null,
"child_entity_ids": null,
"content_tier1": {
"owner": {
"lastName": "Dwane",
"firstName": "Chris"
},
"employer": {
"name": "The Pool Company"
},
"payStubPeriodTo": "2018-12-01"
},
"borrower_name": "Dwane, Chris",
"sales_branch": {
"name": "Houston"
},
"processing_branch": {
"name": "Houston"
}
}


My code

Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim json As String
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim g As String
Dim f As String
Dim h As String
Dim i As String
Dim j As String
Dim l As String
json = My.Computer.FileSystem.ReadAllText("C:\JsonTest.Tx t")
Dim read = Newtonsoft.Json.Linq.JObject.Parse(json)
TextBox1.Text = read.Item("loan_id").ToString
TextBox2.Text = read.Item("content_tier1").ToString
a = TextBox2.Lines(2).Remove(14)
b = TextBox2.Lines(2).Substring(15)
c = TextBox2.Lines(3).Remove(15)
d = TextBox2.Lines(3).Substring(16)
g = TextBox2.Lines(5).Remove(12)
f = TextBox2.Lines(5).Substring(15)
h = TextBox2.Lines(6).Remove(10)
i = TextBox2.Lines(6).Substring(13)
j = TextBox2.Lines(8).Remove(25)
l = TextBox2.Lines(8).Substring(21)
TextBox3.Text = a
TextBox4.Text = b
TextBox5.Text = c
TextBox6.Text = d
TextBox7.Text = g
TextBox8.Text = f
TextBox9.Text = h
TextBox10.Text = i
TextBox11.Text = j
TextBox12.Text = l
End Sub
End Class

Output dapat nyan is

21 blank
owner blank
lastName "Value"
firstName "value"
employer blank
name "Value"
paystubperiod "value"

ang trigger ko po is si content_tier1 kaso ang nagging output po nya is

21 {

mali na po agad sa simula any advice naman po mga master sensya medyo magulo ata explination ko
and baka mabigyan nyo ko idea kung panu ko makukuha yung lahat ng nasa loob ng content_tier1
 
Huwag mo na i-manipulate yung strings dahil gumagamit ka na rin naman ng json library. Gamitin mo yung json library para iextract yung key value na nais mo makuha. Read the documentation. You do not have permission to view the full content of this post. Log in or register now.
 
  • Like
Reactions: rxe
Any reason why you are using Visual Basic? This looks like Visual Basic code (just a disclaimer I am not fond of VB).

You can write the same functionality in Html and JavaScript --easier and contemporary. My 2 cents
 
What you are after is a Linux tool called 'jq'.

user@debian:~/garbage$ jq '.content_tier1.owner.lastName' sample1.txt
"Dwane"
user@debian:~/garbage$ jq '.content_tier1.owner.firstName' sample1.txt
"Chris"

Alternatively, kung gusto mo ng quick 'n dirty method (which is ill-advised), you can use 'sed'

user@debian:~/garbage$ sed -n '/^\s*"ID/,/^\s*"payStubPeriodTo/p' sample1.txt | tr -d '{},'
"ID": 21
"container": "a"
"created_entity_ids": null
"child_entity_ids": null
"content_tier1":
"owner":
"lastName": "Dwane"
"firstName": "Chris"

"employer":
"name": "The Pool Company"

"payStubPeriodTo": "2018-12-01"
 
C#:
using System.Web.Script.Serialization; //Namespace

void jsonParse()
{
    var parsedJsonResult = (new JavaScriptSerializer()).Deserialize<List<CustomerView>>(JsonData);
}

eto gamit ko for deserializing json data..
 
Status
Not open for further replies.

Similar threads

Back
Top