iOS快速,从JSON数组Parse.com检索和删除特定对象

时间:2015-07-28 05:25:58

标签: ios swift parse-platform

如果我们有JSON数据,如何在parse.com中查询和删除?

我有一个JSON数组(如下所示)存储在Parse.com数据库的数据库密钥" JSONArray"并解析类"测试"。现在我想删除包含特定companyName的所有项目。

例如:我想删除与companyName" james"相关的所有内容。即下面的JSON的索引1。

 (
    {
    amount = "20.8";
    companyName = valentino;
    optionalNoteText = "This is test 1 ";
    sPreferenceStatus =         (
                    (
            0,
            0,
            0,
            0,
            0
        )
    );
},
    {
    amount = "52";
    companyName = james;
    optionalNoteText = "This is test 2";
    sPreferenceStatus =         (
                    (
            0,
            1,
            0,
            1,
            0
        )
    );
},
    {
    amount = "10.4";
    companyName = nikki;
    optionalNoteText = “This is test 3”;
    sPreferenceStatus =         (
                    (
            1,
            1,
            1,
            1,
            0
        )
    );
},
    {
    amount = "9.35";
    companyName = jason;
    optionalNoteText = “Test is test 4;
    sPreferenceStatus =         (
                    (
            1,
            0,
            0,
            1,
            0
        )
    );
},
    {
    amount = "8.32";
    companyName = vicky;
    optionalNoteText = "This is test 5";
    sPreferenceStatus =         (
                    (
            0,
            1,
            1,
            0,
            0
        )
    );
}



var findreceivedPostData:PFQuery = PFQuery(className: "Test")
    findreceivedPostData.orderByDescending("createdAt")

//这就是我们通常过滤的方式,在这种情况下,它只是anArray中的当前用户= [" valentino"," jason"," james", "尼基&#34]。

 findreceivedPostData.whereKey("anArray", containedIn: ["\(PFUser.currentUser()!.username!)"])

任何人都知道如何使用JSON?

1 个答案:

答案 0 :(得分:0)

如果要将JSON数据存储为字符串,则需要下载容器对象,修改JSON字符串,然后保存容器。或者,编写一个云代码函数来做同样的事情。将数据存储为像这样的文本并不是很有效,你应该把它建模为指针/关系和类。