1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Latest News: RAGE Multiplayer 0.3.2 Announcement - November 29th, 2017

Question fromJsonArray

Discussion in 'Questions & Suggestions' started by Denis, Jul 3, 2017.

  1. Denis

    Denis Member

    Messages:
    5
    Likes Received:
    0
    Joined:
    Mar 22, 2017
    Hello guys,
    Here is a sample
    Code:
    List<string> first = new List<string> { "te", "te2" };
    string firstJson = API.toJson(first);
    Console.WriteLine(firstJson); // ["te", "te2"]
    
     List<string> second = API.shared.fromJson(firstJson); // produces error message 
    
    Code:
    Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
       в Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
       в Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
       в Main.Server.ResourceController.OnResourceStart()
       в GTANetworkServer.ScriptingEngine.<InvokeResourceStart>b__28_0()
       в GTANetworkServer.ScriptingEngine.MainThreadLoop()
    I tried using fromJsonArray, but here it is upload_2017-7-3_10-36-52.png

    I saw this function on a wiki, and i guess it is what i need, but it's not working
    wiki fromJsonToArray


    Please guys, who knows how to convert JSON text to List<> object, help me
     
  2. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    Hey,
    Try API.fromJson(string json); instead of API.fromJsonArray(); it is possible that this method is now deprecated and both arrays and objects are being handled by fromJson() method.
    I may be wrong. But it's worth a try.
     
  3. Denis

    Denis Member

    Messages:
    5
    Likes Received:
    0
    Joined:
    Mar 22, 2017
    I appreciate your answer, and i thought the same way, but check the head post. When im trying to use .fromJson() for arrays, i get an exception.
    The only way to solve it, is to create a class with just one property of List type and convert it's object to/from json, but its a dirty way..
    May be Network developers forgot to make a method toJsonArray public?
     
  4. Hazes

    Hazes Active Member

    Messages:
    95
    Likes Received:
    21
    Joined:
    Apr 8, 2017
    Yeah. That should be handled by toJsonArray() rather than selfmade dirty methods. We have to wait until devs give their word on this.
     

Share This Page