卜若的代码笔记系列-unity系列-第二章:json2-5002

1.我们返回对象数组时,请注意,来自于服务器的恶意:

2.这个时候我们就需要自行组装字符串了

 

//1.将字符串按','拆解
//2.将字符数组+=‘,’组装
//3.退格+“}”
完成
IEnumerator ieReuqest()
    {
        var request = (HttpWebRequest)WebRequest.Create("http://localhost:8080/move?acc=123&x=33321&y=333123&z=333666");
        var response = (HttpWebResponse)request.GetResponse();
        StreamReader stream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
        string data = stream.ReadToEnd();
        Debug.Log(data);
        string temp = "";
        foreach (char c in data)
        {
            if (c != '[' && c != ']')
            {
                temp += c;
            
            }
        }
        string[] tempArray = temp.Split(',');
        string temp1 = "";
        for (int i = 0; i < tempArray.Length; i++)
        {
            if ((i + 1) % 5 == 0)
            {

                //json的反序列
                Player player = JsonUtility.FromJson<Player>(temp1.Remove(temp1.Length - 1) + "}");
                temp1 = "";
            }
            else
            {
                temp1 += tempArray[i]+",";
            }
        
        }
        response.Close();
        yield return new WaitForSeconds(0.001f);
        
        
    }

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值