Example #1
0
        static void Main(string[] args)
        {
            DataModel      model  = new DataModel();
            FunctionMapper mapper = new FunctionMapper();
            var            ip     = new byte[] { 127, 0, 0, 1 };
            TcpListener    server = new TcpListener(new IPAddress(ip), 8888);

            server.Start();
            Byte[] send       = new byte[50000];
            Byte[] receive    = new byte[5000];
            string jsonString = "";

            Console.WriteLine("Waiting for connection...");
            while (true)
            {
                TcpClient client = server.AcceptTcpClient();
                Console.WriteLine("Connection!...");

                NetworkStream stream = client.GetStream();
                stream.Read(receive, 0, receive.Length);
                string received = Encoding.ASCII.GetString(receive);
                Console.WriteLine(received);
                jsonObject jsono = JsonConvert.DeserializeObject <jsonObject>(received);
                jsonString = mapper.Map(jsono);

                receive  = new byte[5000];
                received = "";

                send = Encoding.UTF8.GetBytes(jsonString);
                stream.Write(send, 0, send.Length);
            }
        }
        /// <summary>
        /// Helper class for collating JSON data on the fly
        /// </summary>
        /// <param name="key">Identity key for the data value</param>
        /// <param name="value">Actual data value to store</param>
        public void AddDataPair(string key, string value)
        {
            // Validate there is both a key and value to work with
            if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
            {
                // Create new object for JSON data
                jsonObject jd = new jsonObject();

                // Assign key and value to the object
                jd.Key = key;
                jd.Value = value;

                // Add JSON data pair to the list
                jsonData.Add(jd);

            }
            else
            {
                // Throw mising argument exception
                throw new ArgumentNullException("One or more expected parameters were null or empty.");
            }
        }
Example #3
0
    public void Main(string args)
    {
        string[] filenames = args.Replace("[[", "").Replace("]]", "").Trim().Split(new string[] { "],[" }, StringSplitOptions.None);
        Console.WriteLine("filenames[0] = " + filenames[0]);
        Console.WriteLine("filenames[1] = " + filenames[1]);

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        // C#でJSONを読み書きしてみる
        // https://hgotoh.jp/wiki/doku.php/documents/windows/windows-024
        DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(jsonObject));
        //FileStream fs = new FileStream(filenames[0], FileMode.Open);
        FileStream fs   = new FileStream("../data1.json", FileMode.Open);
        jsonObject json = (jsonObject)js.ReadObject(fs);

        fs.Close();

        Console.WriteLine(json);

        sw.Stop();
        Console.WriteLine("Execute time ... " + sw.ElapsedMilliseconds.ToString() + "ms\n");
    }
 void Start()
 {
     localPath = Application.json + "/data.json";
     dataExtractedFromJsonFile = File.ReadAllText(localPath);
     jsonObject playerData = JsonUtility.FromJson <jsonObject>(localPath);
 }