如何将SMValue解析为字符串数组

问题描述:

我刚刚熟悉StackMob服务器端自定义代码sdk,我试图获取关系字段并以字符串数组的形式迭代它。我怎么做 ?是否可以遍历它而不解析为数组?如何将SMValue解析为字符串数组

  DataService ds = serviceProvider.getDataService(); 
      List<SMCondition> query = new ArrayList<SMCondition>(); 
      query.add(new SMEquals("product_id", new SMString(jsonObj.getString("product_id")))); 
      List<SMObject> results = ds.readObjects("product", query); 
      SMObject product= results.get(0); 
      //product.getValue().get("categories"); how do i get this to be a String array? 

简单地说,这将是这个样子:

List<SMValue> categories = (List<SMValue>)(rawObj.getValue().get("categories").getValue()); 
for (SMValue smString : categories) { 
    SMString stringValue = (SMString)smString.getValue(); 
    //do whatever you want with the string value here 
} 

显然,在这里一些未经检查的强制转换,所以你会想类型/ null的检查添加到根据相应章节您的数据&架构。

+0

谢谢你的回答 – blackmwana 2013-04-07 13:13:39