Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP7 Json serializer doesn't handle "space"?

I recently made a post here (which is now marked as "answered" - which it is) about parsing Google Calc json strings into WP7 http://www.google.com/ig/calculator?hl=en&q=100GBP=?SEK.

It's working great - unless Google returns a number above 999. A number above 999 is writenn 1 000, instead of 1000. It seems like the "space" makes the application crash/try-catch aware that there's something wrong.

I just wonder how I can make the json serializer (using System.Runtime.Serialization.Json;) (using StringBuilder) return sum/amount(s) above 999, without crashing?

Thanks :)

CODE:

Hello! I'm mainly using the code found here: Parse Google Calculator with Json in Windows Phone 7 / C#?

In order to get currency landcodes from listbox, I use:

        ListBoxItem toExchangeSelected= toCurrencyList.ItemContainerGenerator.ContainerFromItem(this.toCurrencyListtaListe.SelectedItem) as ListBoxItem;
        string toCurrency = toCurrencyList.Content.ToString();
        ListBoxItem fromExchangeSelected= fromCurrencyList.ItemContainerGenerator.ContainerFromItem(this.fromCurrencyList.SelectedItem) as ListBoxItem;
        string fromCurrency = fromExchangeSelected.Content.ToString();
like image 782
AndreasB Avatar asked Dec 20 '25 07:12

AndreasB


1 Answers

Certain European cultures use spaces instead of commas for large numbers, so try using the appropriate CultureInfo before you parse the string:

CultureInfo ci = new CultureInfo("fr-FR");
double d = double.Parse("1 000", ci); // returns 1000.0
like image 159
terphi Avatar answered Dec 22 '25 20:12

terphi