我需要将这个JSON显示到datagridview但属性是变量,我该怎么做?这是JSON字符串:
{
"result":{"count":"57"},
"content_1":{
"message_id":"5526",
"originator":"09366628607",
"message":"Received SMS TEST",
"timestamp":"2017-06-11 22:49:08"
} ,
"content_2":{
"message_id":"5527",
"originator":"09366628607",
"message":"Received SMS TEST",
"timestamp":"2017-06-11 22:49:10"
} ,
"content_3":{
"message_id":"5528",
"originator":"09399139785",
"message":"monday 6.12.2017",
"timestamp":"2017-06-12 05:48:32"
} ,
"content_4":{
"message_id":"5529",
"originator":"09399139785",
"message":"tuesday 6.13.2017",
"timestamp":"2017-06-13 12:51:11"
} ,
"content_5":{
"message_id":"5530",
"originator":"09399139785",
"message":"TAC",
"timestamp":"2017-06-13 16:06:56"
} ,
"content_6":{
"message_id":"5531",
"originator":"09399139785",
"message":"TAC",
"timestamp":"2017-06-13 16:06:58"
} ,
"content_7":{
"message_id":"5532",
"originator":"09399139785",
"message":"TAC aprv 12345667",
"timestamp":"2017-06-13 16:23:16"
} ,
"content_8":{
"message_id":"5533",
"originator":"09399139785",
"message":"TAC inq 1242353",
"timestamp":"2017-06-13 16:30:54"
} ,
"content_9":{
"message_id":"5534",
"originator":"09399139785",
"message":"TAC caol me please asap",
"timestamp":"2017-06-13 18:57:39"
} ,
"content_10":{
"message_id":"5535",
"originator":"09097675705",
"message":"Wakoy labot nimo",
"timestamp":"2017-06-13 20:42:51"
} ,
"content_11":{
"message_id":"5536",
"originator":"09399139785",
"message":"TAC Naku, Ka-TM, temporarily suspended ang TM Easy Plan mo. Pwedeng mag-load muna at gumamit ng prepaid offers. Para maibalik ang plan, magbayad ng bill ngayong araw. Para maibalik ang plan sa susunod na billing cycle, magbayad sa pinakamalapit na 1st or 16th day of the month. I-dial ang *143# > TM Easy Plan > P150 Plan Payment or text TMPlan150 to 8080.",
"timestamp":"2017-06-14 06:04:06"
} ,
"content_12":{
"message_id":"5537",
"originator":"09269787659",
"message":"Magandang umaga dumating naba c rey pls txt b,hnd ks ako poydng 2mawag,tm at globe lang poyd",
"timestamp":"2017-06-14 07:54:35"
} ,
"content_13":{
"message_id":"5538",
"originator":"09399139785",
"message":"TAC Sir maya nlng remote kpag nandito na si sir vincent lumakad pa sila kasi ni sir dindo.",
"timestamp":"2017-06-14 09:32:35"
} ,
"content_14":{
"message_id":"5539",
"originator":"09399139785",
"message":"TAC 192.168.65.36",
"timestamp":"2017-06-14 09:38:02"
} ,
"content_15":{
"message_id":"5540",
"originator":"09399139785",
"message":"TAC Mag-BREAK na tayo! Win P15,000 travel credits this week with promo code GRABTRAVELOKA. Valid for ALL Grab rides til July 7. Learn more: grb.to/GrabTraveloka",
"timestamp":"2017-06-14 10:22:21"
} ,
"content_16":{
"message_id":"5541",
"originator":"09399139785",
"message":"TAC Your One-Time Password (OTP) is 496900, please enter within 5 minutes. Call BDO Customer Contact Center if you did not login to your account. Ref.No.352061",
"timestamp":"2017-06-14 15:11:56"
} ,
"content_17":{
"message_id":"5542",
"originator":"09399139785",
"message":"TAC can u send an email to this address asking for their menu alo_catering@yahoo.com then print it para maka choose ko",
"timestamp":"2017-06-14 18:14:12"
} ,
"content_18":{
"message_id":"5543",
"originator":"09399139785",
"message":"TAC asa naman ka oi!!!",
"timestamp":"2017-06-14 19:19:57"
} ,
"content_19":{
"message_id":"5544",
"originator":"09399139785",
"message":"CDO Roy sori dugay ko naka reply. Duna ko ka istorya sa celfon. Ug walay plan 115 thousand na ang st. Gregory",
"timestamp":"2017-06-14 19:50:49"
} ,
"content_20":{
"message_id":"5545",
"originator":"09399139785",
"message":"CDO Welcome dong",
"timestamp":"2017-06-14 19:51:47"
} ,
"content_21":{
"message_id":"5546",
"originator":"09756631198",
"message":"Magandang gabe po mam.sir wala pa po ba yung plaka ko.Friday kupa nabayaran yon",
"timestamp":"2017-06-14 20:48:25"
} ,
"content_22":{
"message_id":"5547",
"originator":"09399139785",
"message":"TAC Ayos! Pwede ka nang mag-FB up to 50MB valid hanggang 2017-06-16 10:23:39. Pumunta sa m.facebook.com o buksan ang FB app para magsimula. For more inf",
"timestamp":"2017-06-15 08:48:57"
} ,
"content_23":{
"message_id":"5548",
"originator":"09399139785",
"message":"TAC May free access ka sa JOFOM basta't registered sa TM promo. I-download ang app o pumunta sa www.jofom.com. For info, text JOFOM INFO to 8080 for free.",
"timestamp":"2017-06-15 08:49:06"
} ,
"content_24":{
"message_id":"5549",
"originator":"09399139785",
"message":"o, i-text ang FB5 INFO sa 8080. Enjoy!",
"timestamp":"2017-06-15 08:49:19"
} ,
"content_25":{
"message_id":"5550",
"originator":"09399139785",
"message":"TAC Ayos! Pwede ka nang mag-FB up to 50MB valid hanggang 2017-06-16 10:23:39. Pumunta sa m.facebook.com o buksan ang FB app para magsimula. For more inf",
"timestamp":"2017-06-16 08:46:42"
} ,
"content_26":{
"message_id":"5551",
"originator":"09399139785",
"message":"TAC May free access ka sa JOFOM basta't registered sa TM promo. I-download ang app o pumunta sa www.jofom.com. For info, text JOFOM INFO to 8080 for free.",
"timestamp":"2017-06-16 08:46:44"
} ,
"content_27":{
"message_id":"5552",
"originator":"09399139785",
"message":"o, i-text ang FB5 INFO sa 8080. Enjoy!",
"timestamp":"2017-06-16 08:46:45"
} ,
"content_28":{
"message_id":"5553",
"originator":"09399139785",
"message":"TAC May free access ka sa JOFOM basta't registered sa TM promo. I-download ang app o pumunta sa www.jofom.com. For info, text JOFOM INFO to 8080 for free.",
"timestamp":"2017-06-16 10:23:06"
} ,
"content_29":{
"message_id":"5556",
"originator":"09396483334",
"message":"Nakaawid nkun",
"timestamp":"2017-06-17 14:59:06"
} ,
"content_30":{
"message_id":"5557",
"originator":"09108651938",
"message":"Tumawag ako ng 21:20
Di ko kinaya ang mister ko! Dalawa ang jowa nya! Sino ba uunahin kong ligpitin? Este, awayin?
Text KABIT to 5677 now!",
"timestamp":"2017-06-19 21:41:14"
} ,
"content_31":{
"message_id":"5558",
"originator":"09287963825",
"message":"Sir leyte req for overide FDCLeyte. 1/1 SO: D000238275 PRINCEGATE BAYBAY CL: 5.00M OrderVal: 1.63M Expos: 9.14M AvailCr: -4.14M LPay: 06/06/17 HBal: 8.93M OCL: 4.14M OCTDays: 17 Amt: 8,068,994.85 .PDC Details not available or not yet maintained.Dev: CTU/83%/HNU*WBC",
"timestamp":"2017-06-20 09:41:31"
} ,
"content_32":{
"message_id":"5559",
"originator":"09268370555",
"message":"inq D00014419",
"timestamp":"2017-06-22 10:31:48"
} ,
"content_33":{
"message_id":"5560",
"originator":"09177174147",
"message":"Tawag ko later Bos, paabot pako tawag/tex APV",
"timestamp":"2017-06-22 14:33:43"
} ,
"content_34":{
"message_id":"5561",
"originator":"09088731986",
"message":"Aprv D000524568",
"timestamp":"2017-06-22 15:16:28"
} ,
"content_35":{
"message_id":"5562",
"originator":"09753904045",
"message":"Payck-23217-t000225333-18,752.86-PB-1961-7-2-17",
"timestamp":"2017-06-22 17:36:48"
} ,
"content_36":{
"message_id":"5566",
"originator":"09175669795",
"message":"Good am sir. Respectfully im endorsing for your approval. This will be collected tom. This will be delivered once payment is available. Thanks a lot. FDCGenSan. 1/1 SO: D000531595 ADOFELS S CL: 1.71M OrderVal: 0.66M Expos: 1.66M AvailCr: 0.06M LPay: 06/23/17 HBal: 2.02M OCL: -0.06M OCTDays: 10 Amt: 1,033,331.04 .PDC Details not available or not yet maintaine",
"timestamp":"2017-06-23 11:04:10"
} ,
"content_37":{
"message_id":"5568",
"originator":"09268605971",
"message":"PAYCK X 35883 T000488044 104971.54 PB-02362961 6/08/17 B.O 2118.20",
"timestamp":"2017-06-23 11:41:36"
} ,
"content_38":{
"message_id":"5569",
"originator":"09753904045",
"message":"Paych-23223-t000236553
t000236874
338,381.41",
"timestamp":"2017-06-23 17:06:25"
} ,
"content_39":{
"message_id":"5570",
"originator":"09985935310",
"message":"aprv D000111390",
"timestamp":"2017-06-24 10:20:13"
} ,
"content_40":{
"message_id":"5571",
"originator":"09177206294",
"message":"aprv D000111390",
"timestamp":"2017-06-24 11:33:28"
} ,
"content_41":{
"message_id":"5572",
"originator":"09985935310",
"message":"Aprv D000144122",
"timestamp":"2017-06-24 15:23:10"
} ,
"content_42":{
"message_id":"5573",
"originator":"09177206294",
"message":"Aprv D000144122",
"timestamp":"2017-06-24 16:22:39"
} ,
"content_43":{
"message_id":"5574",
"originator":"09985935310",
"message":"aprv D000112090",
"timestamp":"2017-06-24 17:54:52"
} ,
"content_44":{
"message_id":"5575",
"originator":"09399139785",
"message":"mo reply napud samar sir, wla2x man gud signal.ani bohol ug samar.. ma.resolve rani sa migration namo sa receiver sir.. probably within nxt week ma implement na guro namo..",
"timestamp":"2017-06-24 18:42:39"
} ,
"content_45":{
"message_id":"5576",
"originator":"09177206294",
"message":"aprv D000112729",
"timestamp":"2017-06-27 11:05:32"
} ,
"content_46":{
"message_id":"5577",
"originator":"09268370555",
"message":"inq D000147307",
"timestamp":"2017-06-27 14:45:41"
} ,
"content_47":{
"message_id":"5578",
"originator":"09177206294",
"message":"aprv D000112729",
"timestamp":"2017-06-28 10:04:14"
} ,
"content_48":{
"message_id":"5579",
"originator":"09177206294",
"message":"Aprv D000113015",
"timestamp":"2017-06-28 10:55:35"
} ,
"content_49":{
"message_id":"5580",
"originator":"09177206294",
"message":"Aprv D000112729",
"timestamp":"2017-06-28 17:26:03"
} ,
"content_50":{
"message_id":"5581",
"originator":"09177206294",
"message":"Aprv D000114821",
"timestamp":"2017-06-29 10:41:23"
} ,
"content_51":{
"message_id":"5582",
"originator":"09104082749",
"message":"PAYCH X 32718 T000486877 153601.46 T11126 1630.91",
"timestamp":"2017-06-29 15:16:28"
} ,
"content_52":{
"message_id":"5583",
"originator":"09104082749",
"message":"PAYCH X 32718 T000486878 0 T11661 1235.73",
"timestamp":"2017-06-29 15:17:57"
} ,
"content_53":{
"message_id":"5584",
"originator":"09063911933",
"message":"Gud evening! How about the missing proximity card?",
"timestamp":"2017-06-29 20:51:07"
} ,
"content_54":{
"message_id":"5587",
"originator":"09104082749",
"message":"PAYCH X T000486878 200.50",
"timestamp":"2017-06-30 12:01:25"
} ,
"content_55":{
"message_id":"5588",
"originator":"09451174941",
"message":"Fgg",
"timestamp":"2017-06-30 21:21:53"
} ,
"content_56":{
"message_id":"5589",
"originator":"09355571913",
"message":"Me magagawa b di umuwi kna c kim dimkauwi andon p s mao wl msakyan wl n pera ikaw 2mwag ka mama mo ito?",
"timestamp":"2017-07-01 00:11:51"
} ,
"content_57":{
"message_id":"5590",
"originator":"09504242133",
"message":"WORD Today
07/01/17
Gn 18:1-15
Mt 8:5-17
God said, Let there be light. And the universe was born!
The messenger from God said to Abraham, Sarah shall have a son, (1st Reading). And his 90-year old, barren wife gave birth to Isaac!
The angel of God said to the Virgin Mary, You will conceive and give birth to a son. And the Word became Flesh!
God's Word ",
"timestamp":"2017-07-01 07:30:50"
}
}
答案 0 :(得分:0)
使用Json.NET,我认为您需要使用两步转换过程,因为“result”和“content_ *”项目的类型不同。所以,也许是这样的:
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
' Class for "content_*" items
Class ContentItem
Public Property message_id As String
Public Property originator As String
Public Property message As String
Public Property timestamp As String
End Class
' Step 1 - parse JSON to a `Dictionary(Of String, JObject)`:
Dim dict = JsonConvert.DeserializeObject(Of Dictionary(Of String, JObject))(json)
' Step 2 - convert "content_*" items to ContentItem instances using LINQ query
Dim contentItems = (
From key In dict.Keys
Where key.StartsWith("content_")
Select dict(key).ToObject(Of ContentItem)()
).ToList()
然后,您可以将contentItems
绑定到网格。也许有一种方法可以在没有中间JObject的情况下做到这一点,但这并不是太难看。