Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

unexpected character encountered while parsing value , when linker properties set sdk linking only.

REJAHREJAH Member ✭✭✭

unexpected character encountered while parsing value path line 0 position 0 source , when linker properties set sdk linking only. its works fine during json parsing when linking set to none. why its come please help in this regards.

Best Answer

  • REJAHREJAH Member ✭✭✭
    Accepted Answer

    Just skipp
    ing assembly only mono.android and problem have solve

Answers

  • NMackayNMackay GBInsider, University admin
    edited October 2019

    You seriously need to provide more information, Json.NET? Android, iOS?

    Usually you can skip that assembly been linked out in the mtouch arguments.

    Add "--linkskip=Newtonsoft.Json" to the additional mtouch arguments (iOS, remove the -- for Android)

  • NMackayNMackay GBInsider, University admin

    Please respect the forum rules when asking a question, provide more information.

    https://forums.xamarin.com/discussion/87290/xamarin-forum-rules-and-guidelines#latest

  • REJAHREJAH Member ✭✭✭

    its working fine when set Linking None,But when i set Sdk assembly Link its getting above error.
    also try but not succeeded
    Strange sometime work sometime didn't.

  • JarvanJarvan Member, Xamarin Team Xamurai

    Check if your JSON parsing code is correct.

    static readonly JsonSerializer _serializer = new JsonSerializer();
    static readonly HttpClient _client = new HttpClient();
    
    static async Task<T> GetDataObjectFromAPI<T>(string apiUrl)
    {
        using (var stream = await _client.GetStreamAsync(apiUrl).ConfigureAwait(false))
        using (var reader = new StreamReader(stream))
        using (var json = new JsonTextReader(reader))
        {
            if (json == null)
                return default(T);
    
            return _serializer.Deserialize<T>(json);
        }
    }
    

    Similar issue, you can refer to it.
    https://stackoverflow.com/questions/23259173/unexpected-character-encountered-while-parsing-value

  • REJAHREJAH Member ✭✭✭

    Same error facing when linker properties set sdk linking only in release mode.
    Here my code below

    public async static Task<ObservableCollection> GetJsonData1()

            {
    
                  string src [email protected]"https://localwire.me/wp-json/wp/v2/posts/?categories=5&_embed=1&per_page=20";
    
    
    
            ObservableCollection<NewData_Catagories_5_Model> GnfaList = new ObservableCollection<NewData_Catagories_5_Model>();
    
                  using (HttpClient client = new HttpClient())
    
                  {
    
                        var response = await client.GetAsync(src);
    
                        var json = await response.Content.ReadAsStringAsync();
    
                        json = json.Replace("wp:featuredmedia", "wp_featuredmedia");
                        GnfaList = JsonConvert.DeserializeObject<ObservableCollection<NewData_Catagories_5_Model>>(json);
    
    
    
                  }
    
    
    
                  return GnfaList;
    
            }
    

    public class Guid
    {
    public string rendered { get; set; }

      }
    
    public class Title
      {
            public string rendered { get; set; }
    
    
      }
    
    public class Content
      {
            public string rendered { get; set; }
    
    
      }
    
    public class Excerpt
      {
            public string rendered { get; set; }
    
    
      }
    
    public class NewData_Catagories_5_Model
      {
            public string id { get; set; }
            public string date { get; set; }
           // public string date_gmt { get; set; }
            public Guid guid { get; set; }
    
           // public string modified { get; set; }
           // public string modified_gmt { get; set; }
           // public string slug { get; set; }
           // public string status { get; set; }
    
    
           // public string type { get; set; }
           // public string link { get; set; }
            public Title title { get; set; }
            public Content content { get; set; }
    
            public Excerpt excerpt { get; set; }
    
    
    
    
            public string author { get; set; }
    
            public string featured_media { get; set; }
            public string comment_status { get; set; }
           // public string ping_status { get; set; }
    
           // public string sticky { get; set; }
            public string template { get; set; }
            public Embedded _embedded { get; set; }
    
           // public List<Embedded> _embedded { get; set; }
           // public Embedded[] _embedded { get; set; }
    
    
      }
    
    public class Embedded
      {
    
    
            public Author[] author { get; set; }
            public FeatureMedia[] wp_featuredmedia { get; set; }
    
      }
    
    public class Author
      {
    
            [JsonProperty("id")]
            public string id { get; set; }
    
            [JsonProperty("name")]
            public string name { get; set; }
    
    
      }
    
    public class FeatureMedia
      {
    
            [JsonProperty("slug")]
            public string slug { get; set; }
    
            [JsonProperty("id")]
            public string id { get; set; }
    
            [JsonProperty("source_url")]
            public string source_url { get; set; }
    
    
    
    
    
    
      }
    
  • JarvanJarvan Member, Xamarin Team Xamurai

    Please post the JSON data. Or could you please post the sample so that we could find out what happened on your side?

  • REJAHREJAH Member ✭✭✭
    Accepted Answer

    Just skipp
    ing assembly only mono.android and problem have solve

Sign In or Register to comment.