change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal

  • Thread starter Thread starter Benhaddou Soufiane
  • Start date Start date
B

Benhaddou Soufiane

Guest
Hi Devellopers can anybody help me with this i m using xamarin.forms

i need to display the JSON result in the mobile interface for console it's works


i already convert my Json to C# and paste it in new Class JSON1 from json2csharp - generate c# classes from json

this is my code for Homepage.xaml.cs :

dynamic JResponse_Student = JsonConvert.DeserializeObject<List<JSON1>>(result_Student.Content);
ProductsListViews.ItemsSource = JResponse_Student;

//Jresponse_Student Content the JSON deserialize

this is my code for Homepage.xaml :

<ListView x:Name="ProductsListViews">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">


<Label Text="{Binding year}" TextColor="Black"></Label>
<Label Text="{Binding name}" TextColor="Black"></Label>
<Label Text="{Binding surname}" TextColor="Black"></Label>


</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

but i get this error :

Unhandled Exception:

Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object
(e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[University.Data.JSON1]'
because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized
type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type l
ike an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added
to the type to force it to deserialize from a JSON object.
Path 'meta', line 1, position 8. a eu lieu





My Json is :

{"meta":{"service":"student","row_count":18,"year":"2017","params":{"year":"2017","Params":{"service":"student","year":"2017","login_ldap_key_name":"LOGIN RESEAU","login_ldap_key_value":"aaubert","email_key_name":"EMAIL ECOLE","photo_key_name":"PHOTO","cellular_key_name":"PORTABLE"}}},"data":{"id":"AUBERT Antoine","name":"AUBERT","surname":"Antoine","login":"aaubert","mail":"antoine.aubert@epfedu.fr","photo":".jpg","cell_phone":"06 87 99 95 20","annee_universitaire":"2017\/2018","code_formation":"PSFGE1","lib1_formation":"Formation G\u00e9n\u00e9raliste 1\u00e8re Ann\u00e9e (Sceaux)","lib2_formation":"","base_url_photo":"http:\/\/mydata.epf.fr\/nfsdoc\/epf-etp\/ressources\/xfiles\/etudiants\/.jpg","personal_email":"","student_id":"","diplome_type":"INGENIEUR","diplome_code":"EPF FG","diplome_lib":"INGENIEUR Dipl\u00f4me d'ing\u00e9nieur g\u00e9n\u00e9raliste de l'EPF","administrative_status":""}}

Continue reading...
 
Back
Top