现在我正在黑莓手机上工作,我将一些JSON数组解析成String并从中将它转换为Hashtable,就像这样
这是我的JSON字符串
[
{
"StdID":"A1",
"RollNo":"23",
"Class":"First"
},
{
"StdID":"A2",
"RollNo":"13",
"Class":"First"
},
{
"StdID":"A3",
"RollNo":"53",
"Class":"Second"
},
{
"StdID":"A4",
"RollNo":"33",
"Class":"Third"
},
]
我将其解析为哈希表
Hashtable t1=new Hashtable();
t1.put("StdID","A1");
t1.put("RollNo","23");
t1.put("Class","First");
Hashtable t2=new Hashtable();
t2.put("StdID","A2");
t2.put("RollNo","13");
t2.put("Class","First");
Hashtable t3=new Hashtable();
t3.put("StdID","A3");
t3.put("RollNo","53");
t3.put("Class","Second");
Hashtable t4=new Hashtable();
t4.put("StdID","A4");
t4.put("RollNo","33");
t4.put("Class","Third");
Hashtable main=new Hashtable ();
main.put(new Integer(1), t1);
main.put(new Integer(2), t2);
main.put(new Integer(3), t3);
main.put(new Integer(4), t4);
我可以/如何将值检索为
选择拥有头等舱的学生
所以任何人都可以帮助我吗? 这可能是LINQ吗?
答案 0 :(得分:4)
不。 LINQ是.NET的一部分,而不是Java。
答案 1 :(得分:1)
怎么做:
import java.util.Hashtable;
import lombok.ExtensionMethod;
import propel.core.utils.Linq;
import java.util.List;
import lombok.Function;
@ExtensionMethod({Linq.class})
public class Main
{
public static void main(String[] args)
{
Hashtable t1=new Hashtable();
t1.put("StdID","A1");
t1.put("RollNo","23");
t1.put("Class","First");
Hashtable t2=new Hashtable();
t2.put("StdID","A2");
t2.put("RollNo","13");
t2.put("Class","First");
Hashtable t3=new Hashtable();
t3.put("StdID","A3");
t3.put("RollNo","53");
t3.put("Class","Second");
Hashtable t4=new Hashtable();
t4.put("StdID","A4");
t4.put("RollNo","33");
t4.put("Class","Third");
Hashtable main = new Hashtable();
main.put(new Integer(1), t1);
main.put(new Integer(2), t2);
main.put(new Integer(3), t3);
main.put(new Integer(4), t4);
List<Hashtable> result= main.values().where(classEquals("First")).toList();
for(Hashtable ht : result)
System.out.println(ht.get("StdID"));
}
@Function
private static Boolean classEquals(Hashtable table, String _class) {
return table.get("Class") != null && table.get("Class").equals(_class);
}
}
答案 2 :(得分:0)
否 linq适用于 .NET 3.5或更高版本不适用于 JAVA
答案 3 :(得分:0)