0

I'm getting the below response and how do I iterate or get the values?

<__NSSingleObjectArrayI 0x600002edeea0>(
{
    link = "<null>";
    ValueG = "%";
    ValueT = 1;
    ValueV = "5.00";
    ValueS = "%";
    ValueGTX = 1;
    ValueGT = "5.00";
    ValueZH = 1;
    time = 30;
    UG = “test”;
    ValueSFS = "%";
    ValueFT = 1;
    ValueSFV = "5.00";
    SID = “000”;
    SN = Test;
    ST = "";
    ValueTV = "10.00";
    "__type" = “WSDInfo”;
}
)

This is how I tried to get the value, but it is throwing the following error Expected method to read array element not found on object of type 'NSDictionary *'

    self.valuesInfo = [MTLJSONAdapter modelOfClass:self.valueType.storeInfoClass
                                       fromJSONDictionary:JSON
                                                    error:NULL];
NSDictionary *storeInfoDict = JSON;
        if (storeInfoDict.count != 0) {
                    for (int i=0; i <= storeInfoDict.count; i++){
                        NSString *ValueG = storeInfoDict[i][@"ValueG"];
                    }
                }

Below is the response from postman. In the code, "d" is removed by the JSONResponseSerializer

{
    "d": [
        {
            "__type": "WSDInfo",
            "SID": “000”,
            “SN”: “Test”,
            “ST”: "",
            "UG": “Test”,
            "time": "30",
            "ValueTV": "10.00",
            "ValueG": "%",
            "ValueV": "5.00",
            "ValueT": "1",
            "ValueSFS": "%",
            "ValueGT": "5.00",
            "ValueGTX": "1",
            "ValueS": "%",
            "ValueSFV": "5.00",
            "ValueZH": "1",
            "ValueFT": true,
            "link": null
        }
    ]
}
7
  • How is storeInfoDict declared? Commented Feb 10, 2022 at 15:20
  • 1
    What you printed is a NSArray (optimized for handling Single objects), but treat it as a NSArray instance. Inside there is a NSDictionary. But I guess, by the name and the error that storeInfoDict is declared as a NSDictionary. Well, it has only the name of it, because as saiid, it's in fact a NSArray. Commented Feb 10, 2022 at 15:57
  • @Willeke It is stored as NSDictionary Commented Feb 10, 2022 at 17:43
  • 1
    It's declared as a NSDictionary but the value at the end of the pointer is not a NSDictionary, it's a NSArray. Why? How did you get that value? Commented Feb 10, 2022 at 19:17
  • 1
    That's not how you enumerate a NSDictionary, you are enumerating like it was a NSArray. Look how to enumerate a NSDictionary first. Then, the value will be a NSArray, enumerate it too, and then acsess the valueG. Commented Feb 11, 2022 at 7:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.