Unity cannot convert from ‘string’ to ‘int’

Hello i want to parse data that i get from a websocket server but it says “cannot convert from ‘string’ to ‘int’


And when I do then it gives me a wrong number Example:

  • real value: -11.6666342423411
  • value it says: -1.166663424234E + 16
    void Update()
    {
        ws.OnMessage += (sender, e) =>
        {
            JSONNode data = JSON.Parse(e.Data);
            Debug.Log(data);
            // position.x = int.Parse(e.Data["position"]["x"]);
            // position.y = int.Parse(e.Data["position"]["y"]);
            // Debug.Log(position);
            // gameObject.transform.position = position;

            // float rotation = data["rotation"];
            // rb.rotation = rotation;
        };
    }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using WebSocketSharp;
using SimpleJSON;

public class Enemy : MonoBehaviour
{
    public Rigidbody2D rb;

    Vector2 position;

    WebSocket ws;
    void Start()
    {
        ws = new WebSocket("ws://localhost:8080");
        ws.Connect();
    }

    void Update()
    {
        ws.OnMessage += (sender, e) =>
        {
            // JSONNode data = JSON.Parse(e.Data);
            Debug.Log(e.Data["position"]);
            // position.x = int.Parse(e.Data["position"]["x"]);
            // position.y = int.Parse(e.Data["position"]["y"]);
            // Debug.Log(position);
            // gameObject.transform.position = position;

            // float rotation = data["rotation"];
            // rb.rotation = rotation;
        };
    }
}

Leave a Comment