locked
I need help to load json through a Switch files by Uri RRS feed

  • Question

  • A way to load the JSON files according to language can be that within each of the "cases" to create the Uri where the specific language file and passes it directly to the method GetSampleDataAsync() as a parameter.

     switch (CultureInfo.CurrentCulture.Name)
                {
    
    
    
                    case "es-ES":
    
                        Uri data = (new Uri("///Marinas.Shared/es-ES/DataSample.json").;
                        break;
    
    
                    case "en-GB":
                        Uri data = new Uri("///Marinas.Shared/en-GB/DataSample.json");
    
                        break;
    
                    default:
    
                        Uri data = new Uri("///Marinas.Shared/en-GB/DataSample.json");
    
                        break;
    
                }

    as it could convert the variable local data to global

    Wednesday, March 11, 2015 10:21 AM

All replies

  • I don't really know what you're talking about, but you should declare a static Uri variable called "data" in App.Xaml.cs and assign to it:

    App.data = new Uri("///Marinas.Shared/en-GB/DataSample.json");

    Then it will be global.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, March 11, 2015 7:41 PM
    Moderator
  • I want to is to load multiple files json in different languages
    Wednesday, March 11, 2015 7:55 PM
  •  private async Task GetSampleDataAsync()
            {
                
    
    
                if (this._groups.Count != 0)
                    return;
    
                Uri data = new Uri("ms-appx:///DataModel/es-ES/DataSample.json");
                Uri data = new Uri("ms-appx:///DataModel/en-GB/DataSample.json");
                
                StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(data);
                string jsonText = await FileIO.ReadTextAsync(file);
                JsonObject jsonObject = JsonObject.Parse(jsonText);
                JsonArray jsonArray = jsonObject["Groups"].GetArray();
    
                foreach (JsonValue groupValue in jsonArray)
                {
                    JsonObject groupObject = groupValue.GetObject();
                    SampleDataGroup group = new SampleDataGroup(groupObject["UniqueId"].GetString(),
                                                                groupObject["Title"].GetString(),
                                                                groupObject["Subtitle"].GetString(),
                                                                groupObject["ImagePath"].GetString(),
                                                                groupObject["Description"].GetString());
    
                    foreach (JsonValue itemValue in groupObject["Items"].GetArray())
                    {
                        JsonObject itemObject = itemValue.GetObject();
                        group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(),
                                                           itemObject["Title"].GetString(),
                                                           itemObject["Subtitle"].GetString(),
                                                           itemObject["ImagePath"].GetString(),
                                                           itemObject["Description"].GetString(),
                                                           itemObject["Content"].GetString(),
                                                           itemObject["Latitude"].GetString(),
                                                           itemObject["Longitude"].GetString(),
                                                           itemObject["Alatitude"].GetString(),
                                                           itemObject["Blongitude"].GetString(),
                                                           itemObject["Lenght"].GetString(),
                                                           itemObject["Elenght"].GetString(),
                                                           itemObject["Draught"].GetString(),
                                                           itemObject["Ndraught"].GetString(),
                                                           itemObject["Services"].GetString(),
                                                           itemObject["NauticalChart"].GetString(),
                                                           itemObject["Fchart"].GetString(),
                                                           itemObject["Radio"].GetString(),
                                                           itemObject["Dradio"].GetString(),
                                                           itemObject["Function"].GetString(),
                                                           itemObject["Hfunction"].GetString(),
                                                           itemObject["Email"].GetString(),
                                                           itemObject["Addressemail"].GetString()));
                                                          
                                                          
                    }
                    this.Groups.Add(group);
                }
            }
        }

    in sampledatasource.cs in  universal app as I think a global variable having a local variable.

    Uri data=new Uri("ms-appx:///DataModel/es-Es/DataSample.json");

    having several Uri with data that would be local variable as you could turn this global variable

    Thursday, March 12, 2015 8:12 PM
  •  private async Task GetSampleDataAsync()
            {
                
    
    
                if (this._groups.Count != 0)
                    return;
    
                Uri data = new Uri("ms-appx:///DataModel/es-ES/DataSample.json");
                Uri data = new Uri("ms-appx:///DataModel/en-GB/DataSample.json");
                
                StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(data);
                string jsonText = await FileIO.ReadTextAsync(file);
                JsonObject jsonObject = JsonObject.Parse(jsonText);
                JsonArray jsonArray = jsonObject["Groups"].GetArray();
    
                foreach (JsonValue groupValue in jsonArray)
                {
                    JsonObject groupObject = groupValue.GetObject();
                    SampleDataGroup group = new SampleDataGroup(groupObject["UniqueId"].GetString(),
                                                                groupObject["Title"].GetString(),
                                                                groupObject["Subtitle"].GetString(),
                                                                groupObject["ImagePath"].GetString(),
                                                                groupObject["Description"].GetString());
    
                    foreach (JsonValue itemValue in groupObject["Items"].GetArray())
                    {
                        JsonObject itemObject = itemValue.GetObject();
                        group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(),
                                                           itemObject["Title"].GetString(),
                                                           itemObject["Subtitle"].GetString(),
                                                           itemObject["ImagePath"].GetString(),
                                                           itemObject["Description"].GetString(),
                                                           itemObject["Content"].GetString(),
                                                           itemObject["Latitude"].GetString(),
                                                           itemObject["Longitude"].GetString(),
                                                           itemObject["Alatitude"].GetString(),
                                                           itemObject["Blongitude"].GetString(),
                                                           itemObject["Lenght"].GetString(),
                                                           itemObject["Elenght"].GetString(),
                                                           itemObject["Draught"].GetString(),
                                                           itemObject["Ndraught"].GetString(),
                                                           itemObject["Services"].GetString(),
                                                           itemObject["NauticalChart"].GetString(),
                                                           itemObject["Fchart"].GetString(),
                                                           itemObject["Radio"].GetString(),
                                                           itemObject["Dradio"].GetString(),
                                                           itemObject["Function"].GetString(),
                                                           itemObject["Hfunction"].GetString(),
                                                           itemObject["Email"].GetString(),
                                                           itemObject["Addressemail"].GetString()));
                                                          
                                                          
                    }
                    this.Groups.Add(group);
                }
            }
        }

    in sampledatasource.cs in  universal app as I think a global variable having a local variable.

    Uri data=new Uri("ms-appx:///DataModel/es-Es/DataSample.json");

    having several Uri with data that would be local variable as you could turn this global variable

    Based on your current language, set difference json file for data object, what's your current issue now?

    Best Regards,
    Please remember to mark the replies as answers if they help

    Friday, March 13, 2015 9:34 AM
  • The problem of the application is to have it in various languages but having a dynamic universal App as it could with the json files
    Friday, March 13, 2015 10:02 AM