Search code examples
c#jsonunity-game-engineassets

JsonException: Invalid character '.' in input string (Unity)


 public string VERSION = null;
void LoadVersion()
{
#if UNITY_ANDROID
    string full_path = string.Format("{0}/version", Application.streamingAssetsPath);
    string jsonString;

    // Android only use WWW to read file
    WWW reader = new WWW(full_path);
    while (!reader.isDone) { }

    jsonString = reader.text;
    JsonData itemData = JsonMapper.ToObject(jsonString);
#else
    string path = string.Format("{0}/version", Application.streamingAssetsPath);
    StreamReader reader = new StreamReader(path);
    VERSION = reader.ReadToEnd().Trim();
    reader.Close();
#endif
}

I'm having a trouble on this for 6 hours just for this json . Could someone help me please. I don't know why it isn't working .


Solution

  • My bad i didn't scan all the codes on my project i was not suppose to convert it to .json file . I will just read it so basically i will do it like this .

     public string VERSION = null;
     void LoadVersion()
    {
    #if UNITY_ANDROID
    string full_path = string.Format("{0}/version", Application.streamingAssetsPath);
    string jsonString;
    
    // Android only use WWW to read file
    WWW reader = new WWW(full_path);
    while (!reader.isDone) { }
    
    jsonString = reader.text;
    
    #else
    string path = string.Format("{0}/version", Application.streamingAssetsPath);
    StreamReader reader = new StreamReader(path);
    VERSION = reader.ReadToEnd().Trim();
    reader.Close();
    #endif
    }
    

    Am i doing it right . i was just supposed to read my version.file