0

The string I want to pass from one WP page to another contains the character '#'. So when I pass this string using Uri, the rest of the string starting from '#' gets truncated which causes a json parse error. So how else can I pass this string? I don't want to modify the string and pass it as the downloaded string varies from user to user.

Here is my code:

NavigationService.Navigate(new Uri("/Home.xaml?jsonData=" + text, UriKind.Relative));

Here is my json string contained in "text" variable:

{"name":"RALPH K. TELL","course":"","attendence":[{"name":"OBJECT ORIENTED ANALYSIS AND DESIGN","type":"Theory","conducted":"14","present":"14"},{"name":"C#AND.NET FRAMEWORK","type":"Theory","conducted":"17","present":"16"}]}

Here is how I get the value in the next page:

String jdata = NavigationContext.QueryString["jsonData"];
Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
LethalMachine
  • 207
  • 1
  • 2
  • 9

1 Answers1

2

If any of your query strings contain characters that are considered invalid in a Uri what you're doing will fail, as you've discovered. You need to use Uri.EscapeDataString to escape any illegal characters first. Change the code you've posted to the following:

NavigationService.Navigate(new Uri("/Home.xaml?jsonData=" + Uri.EscapeDataString(text), UriKind.Relative));

Have a look at these threads Uri.EscapeDataString() - Invalid URI: The Uri string is too long

HttpUtility.UrlEncode in Windows Phone 7?

Hope it helps!

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82