تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تعبئة الداتا قريد من مصفوفة
#5
في البداية يجب تصحيح كود الjson الموجود في textBox1 لانه كل مجموعة بيانات لم تغلق {

تحتاج المكتبة Newtonsoft.Json.dll
PHP كود :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 
benhe
{
 
   public partial class Form1 Form
    
{
 
       private DataTable table;

 
       public Form1()
 
       {
 
           InitializeComponent();
 
           this.table = new DataTable();
 
           this.table.Columns.Add("tag"typeof(bool));
 
           this.table.Columns.Add("Statu"typeof(Image));
 
           this.table.Columns.Add("number"typeof(string));
 
           this.table.Columns.Add("content"typeof(string));
 
           this.table.Columns.Add("Date"typeof(string));
 
           this.table.Columns.Add("Id"typeof(string));
 
           this.dataGridView1.DataSource this.table;
 
           this.dataGridView1.Columns[0].AutoSizeMode DataGridViewAutoSizeColumnMode.ColumnHeader;
 
           this.dataGridView1.Columns[1].AutoSizeMode DataGridViewAutoSizeColumnMode.ColumnHeader;
 
           this.dataGridView1.Columns[2].AutoSizeMode DataGridViewAutoSizeColumnMode.ColumnHeader;
 
           this.dataGridView1.Columns[3].AutoSizeMode DataGridViewAutoSizeColumnMode.Fill;
 
       }

 
       private void button1_Click(object senderEventArgs e)
 
       {
 
           int num 0;
 
           var jobjects Newtonsoft.Json.JsonConvert.DeserializeObject<List<Newtonsoft.Json.Linq.JObject>>(this.textBox1.Text);
 
           foreach (var o in jobjects)
 
           {
 
               DataRow dr this.table.NewRow();
 
               dr["id"] = (string)o.SelectToken("id");
 
               dr["tag"] = ((string)o.SelectToken("tag") == "1");
 
               dr["number"] = (string)o.SelectToken("number");
 
               dr["content"] = (string)o.SelectToken("content");
 
               String[] = ((string)o.SelectToken("date")).Split(',');
 
               String date String.Format("20{0}/{1}/{2} {3}:{4}:{5}"d[0], d[1], d[2], d[3], d[4], d[5]);
 
               dr["date"] = date;
 
               this.table.Rows.Add(dr);
 
               if ((string)o.SelectToken("tag") == "0"num++;
 
           }
 
           this.toolStripStatusLabel1.Text "Total : " table.Rows.Count;
 
           this.toolStripStatusLabel2.Text "non Lus :" num.ToString();
 
       }
 
   }

بالنسبة لnum الخاص ب non Lus لست متاكد من طريقتها، فقد تحتاج لتعديلها

كود json بعد التصحيح
PHP كود :
[
 
 {
 
   "id""3175",
 
   "number""0125548753",
 
   "content""0056006F00740072002E",
 
   "tag""1",
 
   "date""23,06,22,09,57,41,+4",
 
   "draft_group_id""",
 
   "received_all_concat_sms""0",
 
   "concat_sms_total""2",
 
   "concat_sms_received""3",
 
   "sms_submit_msg_ref""0"
 
 }
 
 ,
 
 {
 
   "id""3173",
 
   "number""532155553",
 
   "content""0056006F0074300330033002E",
 
   "tag""1",
 
   "date""23,06,22,09,57,40,+4",
 
   "draft_group_id""",
 
   "received_all_concat_sms""0",
 
   "concat_sms_total""2",
 
   "concat_sms_received""3",
 
   "sms_submit_msg_ref""0"
 
 }
 
 ,
 
 {
 
   "id""3171",
 
   "number""5353",
 
   "content""0633064A062A06450020062A062C29",
 
   "tag""1",
 
   "date""23,06,22,07,35,42,+4",
 
   "draft_group_id""",
 
   "received_all_concat_sms""0",
 
   "concat_sms_total""3",
 
   "concat_sms_received""4",
 
   "sms_submit_msg_ref""0"
 
 }
 
 ,
 
 {
 
   "id""3163",
 
   "number""215488888",
 
   "content""004C006500200063006C006900606C006F",
 
   "tag""0",
 
   "date""23,06,21,21,48,27,+4",
 
   "draft_group_id""",
 
   "received_all_concat_sms""1",
 
   "concat_sms_total""0",
 
   "concat_sms_received""0",
 
   "sms_submit_msg_ref""0"
 
 }
 
 ,
 
 {
 
   "id""3161",
 
   "number""+213782767990",
 
   "content""00540067006F9526F006F",
 
   "tag""0",
 
   "date""23,06,21,21,38,02,+4",
 
   "draft_group_id""",
 
   "received_all_concat_sms""1",
 
   "concat_sms_total""0",
 
   "concat_sms_received""0",
 
   "sms_submit_msg_ref""0"
 
 }
 
 ,
 
 {
 
   "id""3159",
 
   "number""+213782447578",
 
   "content""063106270646064806256310631",
 
   "tag""0",
 
   "date""23,06,21,21,35,51,+4",
 
   "draft_group_id""",
 
   "received_all_concat_sms""1",
 
   "concat_sms_total""0",
 
   "concat_sms_received""0",
 
   "sms_submit_msg_ref""0"
 
 }
 
 ,
 
 {
 
   "id""3157",
 
   "number""+213782300554",
 
   "content""064625522224606460646",
 
   "tag""0",
 
   "date""23,06,21,21,27,37,+4",
 
   "draft_group_id""",
 
   "received_all_concat_sms""1",
 
   "concat_sms_total""0",
 
   "concat_sms_received""0",
 
   "sms_submit_msg_ref""0"
 
 }
 
 ,
 
 {
 
   "id""3155",
 
   "number""+213332700548",
 
   "content""063303132544210633",
 
   "tag""0",
 
   "date""23,06,21,21,18,40,+4",
 
   "draft_group_id""",
 
   "received_all_concat_sms""1",
 
   "concat_sms_total""0",
 
   "concat_sms_received""0",
 
   "sms_submit_msg_ref""0"
 
 }

الرد }}}
تم الشكر بواسطة: سعود


الردود في هذا الموضوع
RE: تعبئة الداتا قريد من مصفوفة - بواسطة G20 - 22-06-23, 09:19 PM


التنقل السريع :


يقوم بقرائة الموضوع: