- Home /
Json parsing error Unity 5.6
Hi everyone!
I upgraded my project to unity 5.6 and the json parsing function doesn't seem to work anymore:
I get the following error:
InvalidCastException: Cannot cast from source type to destination type.
Here is my code:
//Json string
string json = @" {""Settings"":{""default_language"":""English""},""Languages"":{""English"":""English"",""French"":""Français""}}";
//Json data
JsonData language_config = JsonMapper.ToObject( json );
//Language Settings (add all available languages)
foreach( DictionaryEntry translation in language_config["Languages"] ){
//Get JSON keys / values
var translation_key = translation.Key.ToString();// as string;
var translation_value = translation.Value.ToString();//translation.Value as JsonData;
}
Comment
Tells us nothing. First show us your class that you are trying to get by mapping the object. Second what json framework you are using. Third your json string looks odd.
Here are the librarys I included (only external one is Litjson):
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;
using System.IO;
using UnityEngine.UI;
using LitJson;
On this line:
foreach( DictionaryEntry translation in language_config["Languages"] ){
Your answer
![](https://koobas.hobune.stream/wayback/20220612121916im_/https://answers.unity.com/themes/thub/images/avi.jpg)