2012-11-05 63 views
1

如何在C#中使用Windows.Data.Json將字符串插入到jsonArray中?我想序列化保存到我的localsettings爲Windows 8如何向JsonArray中插入字符串?

我想:

public static void saveString(String myString) 
{ 

    if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("listOfStrings")) 
    { 
     JsonArray jsonArray= new JsonArray(); 
     jsonArray.Add(myString); //error saying it is not a jsonvalue 
     ApplicationData.Current.LocalSettings.Values["listOfStrings"] = jsonArray.ToString(); 
    } 
} 

回答

1

如果你只不會字符串作爲值使用:

JsonArray jsonArray= new JsonArray(); 
jsonArray.Add(JsonValue.CreateStringValue(myString));