Unity Get specific json entry

hello , i am using json.net for first time. I watched full tutorial but I am stuck here.

{
  "Level Name": "1-1",
  "data": {
    "score": 150
  },
  "Level Name": "1-2",
  "data": {
    "score": 130
  },
  "Level Name": "1-3",
  "data": {
    "score": 110
  },
  "Level Name": "1-4",
  "data": {
    "score": 90
  },
  "Level Name": "1-5",
  "data": {
    "score": 70
  }
}

that’s how my json file looks like
I have a level manager that is placed on each level and it sets level and world to 1 and 1 then 1 and 2 etc.
saving is fine

   public void saveScore()
    {
        string savePathFile = Application.persistentDataPath + "/save.sav";

        JObject jObject = new JObject();
        jObject.Add("Level Name", world + "-" + level);
        JObject jDataObject = new JObject();
        jObject.Add("data", jDataObject);
        jDataObject.Add("score", score);

        

        StreamWriter sw = new StreamWriter(savePathFile);
        sw.WriteLine(jObject.ToString());
        sw.Close();

       

        Debug.Log(savePathFile);
    }

but i am not knowing how to load

// to load specific level which has level name as 1-1 here
    public void loadScore()
    {
        string savePathFile = Application.persistentDataPath + "/save.sav";
        StreamReader sr = new StreamReader(savePathFile);
        string s = sr.ReadToEnd();
        sr.Close();

        JObject jobj = JObject.Parse(s);
        Debug.Log(s);


        string[] test = jobj["data"]["score"].ToObject<string[]>();
        foreach (string str in test)
        {
            Debug.Log(str + "");
        }

        //string levelscore = jobj["data"]["score"].Value<string>();


    }

Your json data doesn’t seem to be related to any of your code. Your json data can not be read by most serializers anyways. One object should not have multiple keys with the same name. At the moment you have a single top most object which has multiple “Level Name” and multiple “data” keys. This doesn’t really make much sense. If you want to store multiple levels you should create an array as topmost object and add sub objects where each subobject has a “Level Name” and a “data” key.

Another way is to have an object as top most object and use the level name as key (as long as the level name is unique) and sub objects for each level.

{
    "1-1":{
        "score": 150
    },
    "1-2":{
        "score": 130
    }
}

To save the data like this, do this:

JObject jObject = new JObject();

JObject levelObj = new JObject();
jObject.Add(world + "-" + level, levelObj);
levelObj.Add("score", score);

// […]
// Add more levels

string jsonText= jObject.ToString();

To load the data:

JObject jobj = JObject.Parse(jsonText);

// score of one particular level something like this:
int score = jobj["1-1"]["score"].ToObject<int>();

// To iterate through all levels, something like this:
foreach(JProperty p in jobj)
{
    string name = p.Name.ToObject<string>();
    int score = p.Value.ToObject<int>();
}

I never really use Json.NET since I’ve written SimpleJSON for that. So no guarantee that this works. However Json.NET has a documentation

Your JSON is invalid because a single object has multiple times the same key. You should use an array of objects. And I highly advise you to use types to define what is in your JSON using simple structs.

public struct LevelData
{
    public int score;
}

public struct Level
{
    [JsonProperty(PropertyName="Level Name")] // Not necessary, only if you want to rename the "key" of the property
    public string levelName;
    public LevelData data;


}

public class LevelLoader : MonoBehaviour
{
    private List<Level> levels = new List<Level>();
    private int world;
    private int level;
    private int score;
    private string savePathFile;

    private void Awake()
    {
        savePathFile = Application.persistentDataPath + "/save.sav";
    }
    
    public void saveScore()
    {    
        levels.Add( new Level()
        {
            LevelName = world + "-" + level,
            data = new LevelData()
            {
                score = score
            }
        } );

        // serialize JSON to a string and then write string to a file
        File.WriteAllText( savePathFile, JsonConvert.SerializeObject( levels ) );
    }

    public void loadScore()
    {
        // read file into a string and deserialize JSON to a type
        levels = JsonConvert.DeserializeObject<List<Level>>(File.ReadAllText( savePathFile ) );

        for ( int i = 0 ; i < levels.Count ; i++ )
        {
            Debug.Log( $"{levels_.LevelName} - {levels*.data.score}" );*_

}
}
}