SPListItem拼接成Json格式
- 摘要:可以试着将SPList.Items转化成Json格式。publicstaticstringGetJsonFormSplistItem(SPListItemitem,string[]strArr){stringjson="{";for(inti=0;i<item.ParentList.Fields.Count-1;i++){stringfieldName=item.ParentList.Fields[i].InternalName;ArrayListar=newArrayList()
- 标签:list item JSON JS
可以试着将SPList.Items转化成Json格式。
public static string GetJsonFormSplistItem(SPListItem item, string[] strArr)
{
string json = "{";
for (int i = 0; i < item.ParentList.Fields.Count - 1; i++)
{
string fieldName = item.ParentList.Fields[i].InternalName;
ArrayList ar = new ArrayList();//实例化一个ArrayList
ar.AddRange(strArr);//把数组赋到Arraylist对象
if (ar.Contains(fieldName))
{
if (item[i] != null)
{
json += "\"" + fieldName + "\":\"" + item[i].ToString() + "\",";
}
else
{
json += "\"" + fieldName + "\":\"\",";
}
}
}
json += "},";
return json;
}
public string[] problemRiskArr = { "ProjectName", "ProblemBody", "AffectDegree", "User", "CountermoveBody", "Status" };