0

I have a PHP file and a C# app. In the php file it returns a Array of the rows that i selected from a mysql table. I want to read that Array and deserialize it so the result of a row can be parsed inside a textBlock. My PHP script:

    <?php
mysql_connect("-----", "------", "-----") or
    die("Could not connect: " . mysql_error());
mysql_select_db("------");

$list = array();
$query = "SELECT SongName,ArtistName,Thumbnail,MediaLink FROM Library";
$resource = mysql_query($query);
while($row = mysql_fetch_assoc($resource))
{
   $list['SongName' . (1 + count($list))] = $row['SongName'];
}
$list = array('row' => count($list)) + $list;
echo json_encode(array($list));
?> 

How do i get the ArtistName, Thumbnail and medialink inside the array? How do i read this in C# so my textblock will show: ArtistName. Technologies: Windows 10 Store apps(C#, XAML)

If somebody could help that'd be great,

Christos K

3
  • Why not use Json.NET ( github.com/JamesNK/Newtonsoft.Json )? Commented Aug 2, 2015 at 18:35
  • @stdob-- i know but i don't know the methods to deserialize it! Commented Aug 2, 2015 at 19:02
  • @stdob-- OMG THANK YOU! i used: HttpResponseMessage response = await httpClient.GetAsync("somesite/testt.php"); string array = await response.Content.ReadAsStringAsync(); string json = array; var xd = JsonConvert.DeserializeObject<List<Customer>>(json); foreach (var item in xd) { listView.Items.Add(item.SongName); } Commented Aug 2, 2015 at 19:22

1 Answer 1

1

Simple, you pull all the required data from the database and return it as an array, just put the whole $row into the array you are about to return

<?php
mysql_connect("-----", "------", "-----") or
    die("Could not connect: " . mysql_error());

mysql_select_db("------");

$list = array();

$query = "SELECT SongName,ArtistName,Thumbnail,MediaLink FROM Library";
$resource = mysql_query($query);
while($row = mysql_fetch_assoc($resource))
{
   $list[] = $row;
}

echo json_encode($list);
?> 

Now you should receive all the data you want in the javascript. Just use the javascript debugger to see what it looks like

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.