Lua accessing table stored in external file - lua

I have an external lua file that has a table stored in it that is formatted as follows:
sgeT = {
2535047 = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535047",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "65125",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335843433",
["startTime"] = "Mon Apr 30 22:37:13 2012",
["user"] = "guo",
},
},
2535094 = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535094",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "81635",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335823028",
["startTime"] = "Mon Apr 30 16:57:08 2012",
["user"] = "guo",
},
}
I want to iterate through the table like an array and return the exec key, value pair, and I am completely new to lua and I am using the following script:
FileStr = "lariatData-sgeT-2012-05-31.lua"
Hnd, ErrStd = io.open(FileStr, "r")
myTable = loadTable(FileStr)
if Hnd then
for Str in Hnd:lines() do
print(Str, "\n")
for exec, val in pairs(myTable) do
print(exec.." "..val, "\n")
end
end
Hnd.close()
else
print(ErrStr, "\n")
end
However, it is returning that the table is nil. What am I doing wrong?

In continuation of comments above:
-- Notice that I've used `[2535047]`
sgeT = {
[2535047] = {
{
["account"] = "TG-MCB110105",
["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",
["execEpoch"] = 1305825864,
["execModify"] = "Thu May 19 12:24:24 2011",
["execType"] = "user:binary",
["jobID"] = "2535047",
["numCores"] = "128",
["numNodes"] = "8",
pkgT = {
},
["runTime"] = "65125",
["sha1"] = "e157dd510a7be4d775d6ceb271373ea24e7f9559",
sizeT = {
["bss"] = "104552",
["data"] = "192168",
["text"] = "10650813",
},
["startEpoch"] = "1335843433",
["startTime"] = "Mon Apr 30 22:37:13 2012",
["user"] = "guo",
},
},
}
The above is your file. Then, your Lua program shall be:
FileStr = "lariatData-sgeT-2012-05-31.lua"
Hnd, ErrStr = io.open(FileStr, "r")
if Hnd then
dofile(FileStr)
for Str in Hnd:lines() do
print(Str, "\n")
for exec, val in pairs(sgeT) do
print(exec.." "..val, "\n")
end
end
Hnd.close()
else
print(ErrStr, "\n")
end

Related

Tonemap Fuse for Fusion based on Timothy Lottes algorithm (Lua)

I'm trying to build a Fuse (Fusion studio plugin) based on the tone mapper by Timothy Lottes : http://32ipi028l5q82yhj72224m8j.wpengine.netdna-cdn.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf
presented in this algorithm: https://github.com/Opioid/tonemapper/blob/master/tonemapper.py#L14-L42
The Fuse is accepted by Fusion, but crashes when I'm trying to use it. Could anyone give me some feedback please at what I am doing wrong?
Thanks
(Fuses are written in Lua)
--[[
Tone Mapper based on
http://32ipi028l5q82yhj72224m8j.wpengine.netdna-cdn.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf
https://github.com/Opioid/tonemapper/blob/master/tonemapper.py#L14-L42
version 2021 01 05 by Pieter Dumoulin
]]--
FuRegisterClass("ToneMapper", CT_SourceTool, {
REGS_Category = "Fuses",
REGS_Name = "Tone Mapper",
REGS_OpIconString = "TM",
REGS_OpDescription = "Tone Mapper",
REG_OpNoMask = true
})
function Create()
InContrast = self:AddInput("Contrast", "Contrast", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 5,
INP_Default = 1.2,
})
InShoulder = self:AddInput("Shoulder", "Shoulder", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 5,
INP_Default = 0.97,
})
InMidIn = self:AddInput("Middle Grey In", "mid_in", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 1,
INP_Default = 0.4,
})
InMidOut = self:AddInput("Middle Grey Out", "mid_out", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 1,
INP_Default = 0.18,
})
InHdrMax = self:AddInput("HdrMax", "Hdr_Max", {
LINKID_DataType = "Number",
INPID_InputControl = "SliderControl",
INP_MinAllowed = 0,
INP_MaxScale = 100,
INP_Default = 64,
})
InImage = self:AddInput("Input", "Input", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
OutImage = self:AddOutput("Output", "Output", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
end
function maxrgbfunc()
if p.R == p.G == p.B then return p.G
elseif p.G == math.max(p.R, p.B) then return p.G
elseif p.B == math.max(p.G, p.R) then return p.B
elseif p.R == math.max(p.G, p.B) then return p.R
else return math.max(p.R, math.max(p.G, p.B))
end
function tonemapfunc()
local peak = math.min(maxRGB, self_hdr_max)
local curve = (peak ^ self_a) / (((peak ^ self_a) ^ self_d) * self_b + self_c)
return curve
end
function Process(req)
local img = InImage:GetValue(req)
local a = InContrast:GetValue(req).Value
local d = InShoulder:GetValue(req).Value
local mid_in = InMidIn:GetValue(req).Value
local mid_out = InMidOut:GetValue(req).Value
local hdr_max = InHdrMax:GetValue(req).Value
local ad = a * d
local midi_pow_a = mid_in ^ a
local midi_pow_ad = mid_in ^ ad
local hdrm_pow_a = hdr_max ^ a
local hdrm_pow_ad = hdr_max ^ ad
local u = hdrm_pow_ad * mid_out - midi_pow_ad * mid_out
local v = midi_pow_ad * mid_out
local self_a = a
local self_d = d
local self_b = -((-midi_pow_a + (mid_out * (hdrm_pow_ad * midi_pow_a - hdrm_pow_a * v)) / u) / v)
local self_c = (hdrm_pow_ad * midi_pow_a - hdrm_pow_a * v) / u
local self_hdr_max = hdr_max
local out = Image({IMG_Like = img})
self:DoMultiProcess(nil, { In = img, Out = out, MaxRGB = maxrgb }, img.Height, function (y)
local p = Pixel()
for x=0,In.Width-1 do
In:GetPixel(x,y, p)
maxRGB = maxrgbfunc(x, y, p)
local peak = tonemapfunc(maxRGB, self_hdr_max, self_a, self_d, self_b, self_c, x, y, p)
local ratioR = p.R / maxRGB
local ratioG = p.G / maxRGB
local ratioB = p.B / maxRGB
p.R = peak * ratioR
p.G = peak * ratioG
p.B = peak * ratioB
Out:SetPixel(x,y, p)
end
end)
end
OutImage:Set(req,out)
end

Changing value in table in Lua

I am trying to make a table and want to change a value in that table for a particular key. The thing is when I do change the key it does change for all the keys.
function dump(o, nb)
if nb == nil then
nb = 0
end
if type(o) == 'table' then
local s = ''
for i = 1, nb + 1, 1 do
s = s .. " "
end
s = '{\n'
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
for i = 1, nb, 1 do
s = s .. " "
end
s = s .. '['..k..'] = ' .. dump(v, nb + 1) .. ',\n'
end
for i = 1, nb, 1 do
s = s .. " "
end
return s .. '}'
else
return tostring(o)
end
end
Config={}
PlayersStatusTable={}
Config.DefaultStatus = {
hunger = 1000000,
thirst = 1000000,
}
local timeNow = os.clock()
PlayersStatusTable[12] = Config.DefaultStatus
PlayersStatusTable[112] = Config.DefaultStatus
PlayersStatusTable[54] = Config.DefaultStatus
for playerId, details in pairs(PlayersStatusTable) do
print("playerid1",playerId)
print(dump(PlayersStatusTable))
print(dump(PlayersStatusTable[112]))
print(dump(PlayersStatusTable[112].hunger))
PlayersStatusTable[112].hunger = 5
end
the output is this:
playerid1 112
{
[112] = {
["thirst"] = 1000000,
["hunger"] = 1000000,
},
[54] = {
["thirst"] = 1000000,
["hunger"] = 1000000,
},
[12] = {
["thirst"] = 1000000,
["hunger"] = 1000000,
},
}
{
["thirst"] = 1000000,
["hunger"] = 1000000,
}
1000000
playerid1 54
{
[112] = {
["thirst"] = 1000000,
["hunger"] = 5,
},
[54] = {
["thirst"] = 1000000,
["hunger"] = 5,
},
[12] = {
["thirst"] = 1000000,
["hunger"] = 5,
},
}
{
["thirst"] = 1000000,
["hunger"] = 5,
}
5
playerid1 12
{
[112] = {
["thirst"] = 1000000,
["hunger"] = 5,
},
[54] = {
["thirst"] = 1000000,
["hunger"] = 5,
},
[12] = {
["thirst"] = 1000000,
["hunger"] = 5,
},
}
{
["thirst"] = 1000000,
["hunger"] = 5,
}
5
I just want the hunger of id 112 to be 5.
You're assigning the same table to all 3 keys, so they all point to the same table that's being changed. You need to ensure that you're creating a new table when you assign to each key.
local function shallowCopy(t)
local result = {}
for k, v in pairs(t) do
result[k] = v
end
return result
end
PlayersStatusTable[12] = shallowCopy(Config.DefaultStatus)

IOS App crashes - unrecognized selector sent to instance

In tableView:cellForRowAtIndexpath method, my code is as below.
When I comment out the if condition enclosed in double asterisk(*), the app crashes with the exception mentioned below. And if I uncomment it then it works fine. Please help as I am new to Objective-C.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #“MyTableCell";
cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#“MyTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
**if (invoiceList.count == indexPath.row + 1)**
{
NSMutableDictionary *currentDictionary = [invoiceList objectAtIndex:indexPath.row];
cell.invoiceDetails = currentDictionary;
for ( NSString *key in [cell.invoiceDetails allKeys]) {
NSString *value = [cell.invoiceDetails valueForKey:key];
if([key isEqualToString:MERCHANT_NAME]){
cell.merchantNameValue.text = (value == (id)[NSNull null]) ? #"" : value;
}
if([key isEqualToString:INVOICE_ID]){
cell.invoiceIdValue.text = (value == (id)[NSNull null]) ? #"" : value;
}
if([key isEqualToString:TOTAL_AMOUNT]){
cell.totalAmountValue.text = (value == (id)[NSNull null]) ? #"" : value;
}
}
}
return cell;
}
Exception thrown is:
-[__NSDictionaryM objectAtIndex:]: unrecognized selector sent to instance 0x7fc2a604e9f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM objectAtIndex:]: unrecognized selector sent to instance 0x7fc2a604e9f0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010fbd1f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010f63ebb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010fbd904d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010fb3127c ___forwarding___ + 988
4 CoreFoundation 0x000000010fb30e18 _CF_forwarding_prep_0 + 120
5 MobileWalletBanking 0x000000010cf0037f -[MyViewController tableView:cellForRowAtIndexPath:] + 479
6 UIKit 0x000000010dd9b4b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
7 UIKit 0x000000010dd7afb1 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2846
8 UIKit 0x000000010dd90e3c -[UITableView layoutSubviews] + 213
9 UIKit 0x000000010dd1d973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
10 QuartzCore 0x000000010d2bade8 -[CALayer layoutSublayers] + 150
...
)
EDIT:
NSLog of invoiceList:
{
501 = 72;
610 = Merchant1;
611 = Merchant1;
612 = 51573;
615 = 51573;
616 = "07/08/2015 00:00:00";
617 = "64.01";
618 = 498;
619 = 498;
662 = (
{
501 = 72;
520 = "15.18";
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 43;
621 = "15.18";
623 = True;
624 = 43;
740 = “Text1";
},
{
501 = 72;
520 = 0;
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 10;
621 = 0;
623 = True;
624 = 10;
740 = “Text2";
},
{
501 = 72;
520 = "37.63";
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 2;
621 = "37.63";
623 = True;
624 = 2;
740 = “Text3";
},
{
501 = 72;
520 = "11.20";
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 3;
621 = "11.20";
623 = True;
624 = 3;
740 = “Text4";
},
{
501 = 72;
520 = 0;
615 = 51573;
616 = "07/08/2015 00:00:00";
620 = 14;
621 = 0;
623 = True;
624 = 14;
740 = “Text5";
}
);
663 = (
(
{
Key = 501;
Value = 83;
},
{
Key = Name;
Value = "INVOICE_CONNECTION_PROPERTIES";
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 610;
Value = "";
},
{
Key = 615;
Value = 51573;
},
{
Key = 620;
Value = 1;
},
{
Key = "SERVICE_NAME";
Value = “Text1";
},
{
Key = "FIELD_1";
Value = 4272035;
},
{
Key = "FIELD_1_CONNECTION_FIELD_ID";
Value = 000000000000481;
},
{
Key = "FIELD_1_QS_NAME";
Value = "Id";
},
{
Key = "FIELD_1_QS_VALUE";
Value = "Id";
},
{
Key = "FIELD_2";
Value = 10;
},
{
Key = "FIELD_2_CONNECTION_FIELD_ID";
Value = 000000000000482;
},
{
Key = "FIELD_2_QS_NAME";
Value = "index1";
},
{
Key = "FIELD_2_QS_VALUE";
Value = "index1";
},
{
Key = "FIELD_3";
Value = "";
},
{
Key = "FIELD_3_IS_MODIFIED";
Value = 1;
},
{
Key = "FIELD_3_CONNECTION_FIELD_ID";
Value = 000000000000483;
},
{
Key = "FIELD_3_QS_NAME";
Value = "index2";
},
{
Key = "FIELD_3_QS_VALUE";
Value = "index2";
},
{
Key = "FIELD_4";
Value = R;
},
{
Key = "FIELD_4_CONNECTION_FIELD_ID";
Value = 000000000000488;
},
{
Key = "FIELD_4_QS_NAME";
Value = "index_Type";
},
{
Key = "FIELD_4_QS_VALUE";
Value = "Index_Type";
}
),
(
{
Key = 501;
Value = 83;
},
{
Key = Name;
Value = "INVOICE_CONNECTION_PROPERTIES";
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 610;
Value = "";
},
{
Key = 615;
Value = 51573;
},
{
Key = 620;
Value = 2;
},
{
Key = "SERVICE_NAME";
Value = “Text2";
},
{
Key = "FIELD_1";
Value = 4272033;
},
{
Key = "FIELD_1_CONNECTION_FIELD_ID";
Value = 000000000000481;
},
{
Key = "FIELD_1_QS_NAME";
Value = "Id";
},
{
Key = "FIELD_1_QS_VALUE";
Value = "Id";
},
{
Key = "FIELD_2";
Value = 3;
},
{
Key = "FIELD_2_CONNECTION_FIELD_ID";
Value = 000000000000482;
},
{
Key = "FIELD_2_QS_NAME";
Value = "index1";
},
{
Key = "FIELD_2_QS_VALUE";
Value = "index1";
},
{
Key = "FIELD_3";
Value = "";
},
{
Key = "FIELD_3_IS_MODIFIED";
Value = 1;
},
{
Key = "FIELD_3_CONNECTION_FIELD_ID";
Value = 000000000000483;
},
{
Key = "FIELD_3_QS_NAME";
Value = "index2";
},
{
Key = "FIELD_3_QS_VALUE";
Value = "index2";
},
{
Key = "FIELD_4";
Value = C;
},
{
Key = "FIELD_4_CONNECTION_FIELD_ID";
Value = 000000000000488;
},
{
Key = "FIELD_4_QS_NAME";
Value = "index_type";
},
{
Key = "FIELD_4_QS_VALUE";
Value = "index_type";
}
)
);
664 = (
(
{
Key = 501;
Value = 73;
},
{
Key = 625;
Value = 000000000000481;
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 626;
Value = "id";
},
{
Key = 627;
Value = 1;
},
{
Key = 590;
Value = True;
}
),
(
{
Key = 501;
Value = 73;
},
{
Key = 625;
Value = 000000000000482;
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 626;
Value = "index1";
},
{
Key = 627;
Value = 2;
},
{
Key = 590;
Value = True;
}
),
(
{
Key = 501;
Value = 73;
},
{
Key = 625;
Value = 000000000000483;
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 626;
Value = "index2";
},
{
Key = 627;
Value = 3;
},
{
Key = 590;
Value = True;
}
),
(
{
Key = 501;
Value = 73;
},
{
Key = 625;
Value = 000000000000488;
},
{
Key = 611;
Value = Merchant1;
},
{
Key = 626;
Value = "index_type";
},
{
Key = 627;
Value = 4;
},
{
Key = 590;
Value = True;
}
)
);
}
You are checking if (invoiceList.count == indexPath.row + 1) but instead of it, use if (invoiceList.count> indexPath.row ). Please also check "numberOfRowsInIndexpath" is returning as invoiceList.count.

Mean/median/mode from complex table in lua

Thank you for all the support with lua, I'm very new and my application is working nicely so far.
I've made an app that will take in a few thousand numbers for different items. I'm trying to find the Mean/Media/Mode for each item, I've been able to do this for a single item, but not for all items.
Here is my table structure:
for i = 0, 1500 do
local e = {}
e.seller,
e.buyer,
e.itemName,
e.soldAmount = GetSoldAmount(FromMember(i))
table.insert(allSalesTempTable, e)
end
Table output format
[1] =
{
["itemName"] = [[Salad]]
["buyer"] = [[#Mike]],
["eventType"] = 15,
["soldAmount"] = 150,
["seller"] = [[#Sarah]],
},
[2] =
{
["itemName"] = [Pizza]
["buyer"] = [[#James]],
["eventType"] = 15,
["soldAmount"] = 150,
["seller"] = [[#Sarah]],
},
[3] =
{
["itemName"] = [Salad]
["buyer"] = [[#Frank]],
["eventType"] = 15,
["soldAmount"] = 75,
["seller"] = [[#Sarah]],
},
[4] ...
},
Then I'm trying to send the table/array to this mean function
stats={}
-- Get the mean value of a table
function stats.mean( t )
local sum = 0
local count= 0
local tempTbl = {}
(This is completely not going to work, but its what I'm trying so far)
for k,v in pairs(t) do tempTbl[k] = v
if v.itemName == tempTbl.itemName then
sum = sum + v.soldAmount
count = count + 1
end
end
return (sum / count)
end
--- To get the function started
stats.mean(e)
Here is where I'm getting fuzzy, Not sure if I can add the MEAN while collecting the data into the first temp table, or if it needs to be re-calculated after I have all the data?
If it needs to be done after, then my stats.mean(e) needs a way to insert it?
I'm trying to get this output:
[1] =
{
["itemName"] = [[Salad]]
["buyer"] = [[#Mike]],
["eventType"] = 15,
["soldAmount"] = 150,
["seller"] = [[#Sarah]],
["mean"] = 112.5 - New Insert somehow
},
[2] =
{
["itemName"] = [Pizza]
["buyer"] = [[#James]],
["eventType"] = 15,
["soldAmount"] = 150,
["seller"] = [[#Sarah]],
["mean"] = 150 - New Insert somehow
},
[3] =
{
["itemName"] = [Salad]
["buyer"] = [[#Frank]],
["eventType"] = 15,
["soldAmount"] = 75,
["seller"] = [[#Sarah]],
["mean"] = 112.5 - New Insert somehow
},
[4] ...
},
I've been working on this problem for a few days, After I see how to adjust my format for the mean and insert into the existing table I'll be able to figure out mean/min/max/median/mode easy enough.

How to parse this string received from TMDB in iOS

I am getting the popular movie data from TMDB in my iOS App. however i am having great trouble in parsing and getting the meaningful data from it. I am totally new to iOS. i have done similar thing in Windows Phone, where i created Poco's and used DataContractJsonSerializer to parse the data.
but i am not getting any idea on how to do this in iOS.
I want to retrieve id, original_title and poster path from this string.
this is the data i am getting
{
buffer = {
0 = 123;
1 = 34;
10 = 34;
100 = 114;
3451 = 34;
3452 = 58;
3453 = 52;
3454 = 54;
3455 = 46;
3456 = 55;
3457 = 50;
3458 = 49;
3459 = 54;
346 = 110;
3460 = 49;
3461 = 48;
// lot of number in between
977 = 87;
978 = 75;
979 = 68;
98 = 34;
980 = 108;
981 = 51;
982 = 88;
983 = 97;
984 = 98;
985 = 99;
986 = 112;
987 = 72;
988 = 82;
989 = 110;
99 = 111;
990 = 110;
991 = 76;
992 = 77;
993 = 75;
994 = 102;
995 = 85;
996 = 46;
997 = 106;
998 = 112;
999 = 103;
length = 5810;
};
};
cookies = {
};
data = {
page = 1;
results = (
{
adult = 0;
"backdrop_path" = "/AdRL6c4BoMJgk7ZFUB2oUVzav2p.jpg";
id = 41602;
"original_title" = "The Necessary Death of Charlie Countryman";
popularity = "110.726084305053";
"poster_path" = "/fSwdCCGmO50IMaH4XMAixjclLDF.jpg";
"release_date" = "2013-11-15";
title = "The Necessary Death of Charlie Countryman";
"vote_average" = "7.5";
"vote_count" = 37;
},
{
adult = 0;
"backdrop_path" = "/mrvlpJFAzKwZZkLm9VD7Rh2VECi.jpg";
id = 116745;
"original_title" = "The Secret Life of Walter Mitty";
popularity = "64.2212199623452";
"poster_path" = "/v3e1LdwTXupH9L78eIWCKBjclhJ.jpg";
"release_date" = "2013-12-25";
title = "The Secret Life of Walter Mitty";
"vote_average" = "7.2";
"vote_count" = 124;
},
{
adult = 0;
"backdrop_path" = "/8aZHR0wXacn5DVYK3cS2ozWYPCN.jpg";
id = 64686;
"original_title" = "47 Ronin";
popularity = "95.9101659814315";
"poster_path" = "/v9JCVROrdlHZCWP3D6pnV8Xc29w.jpg";
"release_date" = "2013-12-25";
title = "47 Ronin";
"vote_average" = "6.5";
"vote_count" = 81;
},
{
adult = 0;
"backdrop_path" = "/zZTyJ6fbWKDl3XabcpHRnnLMKfU.jpg";
id = 249397;
"original_title" = "Nymphomaniac: Vol. II";
popularity = "94.03616025076791";
"poster_path" = "/pCW6krILJ2L0rXDXH0715teKTtm.jpg";
"release_date" = "2014-03-20";
title = "Nymphomaniac: Vol. II";
"vote_average" = "6.8";
"vote_count" = 11;
},
{
adult = 0;
"backdrop_path" = "/hyR7Fs6Tepgu3yCQGtgO4Ilz9tY.jpg";
id = 57158;
"original_title" = "The Hobbit: The Desolation of Smaug";
popularity = "88.3637510164635";
"poster_path" = "/gQCiuxGsfiXH1su6lp9n0nd0UeH.jpg";
"release_date" = "2013-12-13";
title = "The Hobbit: The Desolation of Smaug";
"vote_average" = "7.6";
"vote_count" = 434;
},
{
adult = 0;
"backdrop_path" = "/cAhCDpAq80QCeQvHytY9JkBalpH.jpg";
id = 109445;
"original_title" = Frozen;
popularity = "69.4628746979819";
"poster_path" = "/jIjdFXKUNtdf1bwqMrhearpyjMj.jpg";
"release_date" = "2013-11-19";
title = Frozen;
"vote_average" = "7.7";
"vote_count" = 348;
},
{
adult = 0;
"backdrop_path" = "/rP36Rx5RQh0rmH2ynEIaG8DxbV2.jpg";
id = 106646;
"original_title" = "The Wolf of Wall Street";
popularity = "64.6183486216064";
"poster_path" = "/wAgdJRx4uZ0u4uzu34NOMvtjLAR.jpg";
"release_date" = "2013-12-25";
title = "The Wolf of Wall Street";
"vote_average" = "7.9";
"vote_count" = 330;
},
{
adult = 0;
"backdrop_path" = "/r7Lmi2Jj1CJLdipYtLEU5iA4SB5.jpg";
id = 64807;
"original_title" = "Grudge Match";
popularity = "59.9853953814402";
"poster_path" = "/vzIIna3nvQAVGBBXbZgzvPSxg36.jpg";
"release_date" = "2013-12-25";
title = "Grudge Match";
"vote_average" = "6.6";
"vote_count" = 16;
},
{
adult = 0;
"backdrop_path" = "/mnxWdWTP3jbfxC4oaPrwevwvOZ2.jpg";
id = 53182;
"original_title" = "300: Rise of an Empire";
popularity = "49.8372271195572";
"poster_path" = "/d4kPMHsoTEH3FIkBDJM0uVOlas6.jpg";
"release_date" = "2014-03-07";
title = "300: Rise of an Empire";
"vote_average" = "6.6";
"vote_count" = 102;
},
{
adult = 0;
"backdrop_path" = "/rO75nODBBmJx4u5ZRy2BsGFgbO7.jpg";
id = 177494;
"original_title" = "Veronica Mars";
popularity = "48.7870515185193";
"poster_path" = "/nS3L07mQfcNJcisLEKgi8fWoBS1.jpg";
"release_date" = "2014-03-14";
title = "Veronica Mars";
"vote_average" = "7.2";
"vote_count" = 19;
},
{
adult = 0;
"backdrop_path" = "/iJtq3PHsLgjcYIrNlT2glzEdBo5.jpg";
id = 110415;
"original_title" = Snowpiercer;
popularity = "47.3945315956173";
"poster_path" = "/3J4QoMpQYE2MehOTQG9X2KUP4aq.jpg";
"release_date" = "2013-08-01";
title = Snowpiercer;
"vote_average" = "7.2";
"vote_count" = 29;
},
{
adult = 0;
"backdrop_path" = "/qMDiCjxfv6Y8JN2DFViTX5D1ORH.jpg";
id = 24253;
"original_title" = "Flickan som lekte med elden";
popularity = "46.7216104479466";
"poster_path" = "/qHRpU2d9NWB0WDulwgFwg6a9JRK.jpg";
"release_date" = "2009-09-18";
title = "The Girl Who Played with Fire";
"vote_average" = "6.8";
"vote_count" = 141;
},
{
adult = 0;
"backdrop_path" = "/1DfcGAQ4EVIZFnveo1IzHFtgFTS.jpg";
id = 175112;
"original_title" = "The Pirate Fairy";
popularity = "46.03463240154";
"poster_path" = "/6VmPnBPDCTbpZ3Jj5lbgHD10IZm.jpg";
"release_date" = "2014-04-01";
title = "The Pirate Fairy";
"vote_average" = "7.6";
"vote_count" = 5;
},
{
adult = 0;
"backdrop_path" = "/1RTiQXeHoEMXkZNWaB8W5uaEZ2.jpg";
id = 205220;
"original_title" = Philomena;
popularity = "45.1210557523094";
"poster_path" = "/6BTXHupSPkrwsoz4Br6qwwSVmhj.jpg";
"release_date" = "2013-11-27";
title = Philomena;
"vote_average" = "7.5";
"vote_count" = 31;
},
{
adult = 0;
"backdrop_path" = "/wRCPG1lsgfTFkWJ7G3eWgxCgv0C.jpg";
id = 101299;
"original_title" = "The Hunger Games: Catching Fire";
popularity = "41.4568100606251";
"poster_path" = "/tAhSyLxpaZJCr1oc2a3flvC2B7x.jpg";
"release_date" = "2013-11-22";
title = "The Hunger Games: Catching Fire";
"vote_average" = "7.7";
"vote_count" = 518;
},
{
adult = 0;
"backdrop_path" = "/hz3JfAikYXtaNWIJhWM4p5sy5OZ.jpg";
id = 49047;
"original_title" = Gravity;
popularity = "40.0573419755177";
"poster_path" = "/2gPjLWIyrWlAn2DgKMOKTBnZYyO.jpg";
"release_date" = "2013-10-04";
title = Gravity;
"vote_average" = "7.9";
"vote_count" = 751;
},
{
adult = 0;
"backdrop_path" = "/3FweBee0xZoY77uO1bhUOlQorNH.jpg";
id = 76338;
"original_title" = "Thor: The Dark World";
popularity = "38.5511611536454";
"poster_path" = "/aROh4ZwLfv9tmtOAsrnkYTbpujA.jpg";
"release_date" = "2013-11-08";
title = "Thor: The Dark World";
"vote_average" = "7.1";
"vote_count" = 503;
},
{
adult = 0;
"backdrop_path" = "/dNPmXYRS3nN4vD7MLtz5lP79DCB.jpg";
id = 11824;
"original_title" = "Teen Wolf";
popularity = "37.546317184227";
"poster_path" = "/3TKJbKNpHvRP8YVnwbgfok41AAC.jpg";
"release_date" = "1985-08-23";
title = "Teen Wolf";
"vote_average" = "7.1";
"vote_count" = 31;
},
{
adult = 0;
"backdrop_path" = "/kJzvjhJP6Xf7QQofVl3y0NvpwmI.jpg";
id = 256731;
"original_title" = "Bad Country";
popularity = "37.123709776744";
"poster_path" = "/6bjfGrtUYmuZzFCia3TcvY0Kz1e.jpg";
"release_date" = "2014-03-10";
title = "Bad Country";
"vote_average" = "5.5";
"vote_count" = 3;
},
{
adult = 0;
"backdrop_path" = "/6Ace8kIosYGnAiJUHgbLO4MNI6k.jpg";
id = 77067;
"original_title" = DeadHeads;
popularity = "36.41";
"poster_path" = "/A7kD47MEXywqKPeKHrxBfkvPTqy.jpg";
"release_date" = "2011-04-29";
title = DeadHeads;
"vote_average" = "5.8";
"vote_count" = 6;
}
);
"total_pages" = 7848;
"total_results" = 156953;
};
headers = {
"Access-Control-Allow-Origin" = "*";
Age = 3350;
"Cache-Control" = "public, max-age=14400";
Connection = "keep-alive";
"Content-Length" = 5810;
"Content-Type" = "application/json;charset=utf-8";
Date = "Sat, 29 Mar 2014 10:14:03 GMT";
ETag = "\"76070c8ebb216a66cbbc36e56c1407fa\"";
Server = nginx;
Status = "200 OK";
Vary = "Accept-Encoding";
Via = "1.0 localhost (squid/3.1.19)";
"X-Apiary-Ratelimit-Limit" = 120;
"X-Apiary-Ratelimit-Remaining" = 119;
"X-Apiary-Transaction-Id" = 53369cebed260702000005cc;
"X-Cache" = "HIT from localhost";
"X-Cache-Lookup" = "HIT from localhost:3128";
"X-Memc" = HIT;
"X-Memc-Age" = 12648;
"X-Memc-Expires" = 1752;
"X-Memc-Key" = eb13032fb1ef09086dcaac2d14c098c0;
};
status = 200;
text = "{\"page\":1,\"results\":[{\"adult\":false,\"backdrop_path\":\"/AdRL6c4BoMJgk7ZFUB2oUVzav2p.jpg\",\"id\":41602,\"original_title\":\"The Necessary Death of Charlie Countryman\",\"release_date\":\"2013-11-15\",\"poster_path\":\"/fSwdCCGmO50IMaH4XMAixjclLDF.jpg\",\"popularity\":110.726084305053,\"title\":\"The Necessary Death of Charlie Countryman\",\"vote_average\":7.5,\"vote_count\":37},{\"adult\":false,\"backdrop_path\":\"/mrvlpJFAzKwZZkLm9VD7Rh2VECi.jpg\",\"id\":116745,\"original_title\":\"The Secret Life of Walter Mitty\",\"release_date\":\"2013-12-25\",\"poster_path\":\"/v3e1LdwTXupH9L78eIWCKBjclhJ.jpg\",\"popularity\":64.2212199623452,\"title\":\"The Secret Life of Walter Mitty\",\"vote_average\":7.2,\"vote_count\":124},{\"adult\":false,\"backdrop_path\":\"/8aZHR0wXacn5DVYK3cS2ozWYPCN.jpg\",\"id\":64686,\"original_title\":\"47 Ronin\",\"release_date\":\"2013-12-25\",\"poster_path\":\"/v9JCVROrdlHZCWP3D6pnV8Xc29w.jpg\",\"popularity\":95.9101659814315,\"title\":\"47 Ronin\",\"vote_average\":6.5,\"vote_count\":81},{\"adult\":false,\"backdrop_path\":\"/zZTyJ6fbWKDl3XabcpHRnnLMKfU.jpg\",\"id\":249397,\"original_title\":\"Nymphomaniac: Vol. II\",\"release_date\":\"2014-03-20\",\"poster_path\":\"/pCW6krILJ2L0rXDXH0715teKTtm.jpg\",\"popularity\":94.0361602507679,\"title\":\"Nymphomaniac: Vol. II\",\"vote_average\":6.8,\"vote_count\":11},{\"adult\":false,\"backdrop_path\":\"/hyR7Fs6Tepgu3yCQGtgO4Ilz9tY.jpg\",\"id\":57158,\"original_title\":\"The Hobbit: The Desolation of Smaug\",\"release_date\":\"2013-12-13\",\"poster_path\":\"/gQCiuxGsfiXH1su6lp9n0nd0UeH.jpg\",\"popularity\":88.3637510164635,\"title\":\"The Hobbit: The Desolation of Smaug\",\"vote_average\":7.6,\"vote_count\":434},{\"adult\":false,\"backdrop_path\":\"/cAhCDpAq80QCeQvHytY9JkBalpH.jpg\",\"id\":109445,\"original_title\":\"Frozen\",\"release_date\":\"2013-11-19\",\"poster_path\":\"/jIjdFXKUNtdf1bwqMrhearpyjMj.jpg\",\"popularity\":69.4628746979819,\"title\":\"Frozen\",\"vote_average\":7.7,\"vote_count\":348},{\"adult\":false,\"backdrop_path\":\"/rP36Rx5RQh0rmH2ynEIaG8DxbV2.jpg\",\"id\":106646,\"original_title\":\"The Wolf of Wall Street\",\"release_date\":\"2013-12-25\",\"poster_path\":\"/wAgdJRx4uZ0u4uzu34NOMvtjLAR.jpg\",\"popularity\":64.6183486216064,\"title\":\"The Wolf of Wall Street\",\"vote_average\":7.9,\"vote_count\":330},{\"adult\":false,\"backdrop_path\":\"/r7Lmi2Jj1CJLdipYtLEU5iA4SB5.jpg\",\"id\":64807,\"original_title\":\"Grudge Match\",\"release_date\":\"2013-12-25\",\"poster_path\":\"/vzIIna3nvQAVGBBXbZgzvPSxg36.jpg\",\"popularity\":59.9853953814402,\"title\":\"Grudge Match\",\"vote_average\":6.6,\"vote_count\":16},{\"adult\":false,\"backdrop_path\":\"/mnxWdWTP3jbfxC4oaPrwevwvOZ2.jpg\",\"id\":53182,\"original_title\":\"300: Rise of an Empire\",\"release_date\":\"2014-03-07\",\"poster_path\":\"/d4kPMHsoTEH3FIkBDJM0uVOlas6.jpg\",\"popularity\":49.8372271195572,\"title\":\"300: Rise of an Empire\",\"vote_average\":6.6,\"vote_count\":102},{\"adult\":false,\"backdrop_path\":\"/rO75nODBBmJx4u5ZRy2BsGFgbO7.jpg\",\"id\":177494,\"original_title\":\"Veronica Mars\",\"release_date\":\"2014-03-14\",\"poster_path\":\"/nS3L07mQfcNJcisLEKgi8fWoBS1.jpg\",\"popularity\":48.7870515185193,\"title\":\"Veronica Mars\",\"vote_average\":7.2,\"vote_count\":19},{\"adult\":false,\"backdrop_path\":\"/iJtq3PHsLgjcYIrNlT2glzEdBo5.jpg\",\"id\":110415,\"original_title\":\"Snowpiercer\",\"release_date\":\"2013-08-01\",\"poster_path\":\"/3J4QoMpQYE2MehOTQG9X2KUP4aq.jpg\",\"popularity\":47.3945315956173,\"title\":\"Snowpiercer\",\"vote_average\":7.2,\"vote_count\":29},{\"adult\":false,\"backdrop_path\":\"/qMDiCjxfv6Y8JN2DFViTX5D1ORH.jpg\",\"id\":24253,\"original_title\":\"Flickan som lekte med elden\",\"release_date\":\"2009-09-18\",\"poster_path\":\"/qHRpU2d9NWB0WDulwgFwg6a9JRK.jpg\",\"popularity\":46.7216104479466,\"title\":\"The Girl Who Played with Fire\",\"vote_average\":6.8,\"vote_count\":141},{\"adult\":false,\"backdrop_path\":\"/1DfcGAQ4EVIZFnveo1IzHFtgFTS.jpg\",\"id\":175112,\"original_title\":\"The Pirate Fairy\",\"release_date\":\"2014-04-01\",\"poster_path\":\"/6VmPnBPDCTbpZ3Jj5lbgHD10IZm.jpg\",\"popularity\":46.03463240154,\"title\":\"The Pirate Fairy\",\"vote_average\":7.6,\"vote_count\":5},{\"adult\":false,\"backdrop_path\":\"/1RTiQXeHoEMXkZNWaB8W5uaEZ2.jpg\",\"id\":205220,\"original_title\":\"Philomena\",\"release_date\":\"2013-11-27\",\"poster_path\":\"/6BTXHupSPkrwsoz4Br6qwwSVmhj.jpg\",\"popularity\":45.1210557523094,\"title\":\"Philomena\",\"vote_average\":7.5,\"vote_count\":31},{\"adult\":false,\"backdrop_path\":\"/wRCPG1lsgfTFkWJ7G3eWgxCgv0C.jpg\",\"id\":101299,\"original_title\":\"The Hunger Games: Catching Fire\",\"release_date\":\"2013-11-22\",\"poster_path\":\"/tAhSyLxpaZJCr1oc2a3flvC2B7x.jpg\",\"popularity\":41.4568100606251,\"title\":\"The Hunger Games: Catching Fire\",\"vote_average\":7.7,\"vote_count\":518},{\"adult\":false,\"backdrop_path\":\"/hz3JfAikYXtaNWIJhWM4p5sy5OZ.jpg\",\"id\":49047,\"original_title\":\"Gravity\",\"release_date\":\"2013-10-04\",\"poster_path\":\"/2gPjLWIyrWlAn2DgKMOKTBnZYyO.jpg\",\"popularity\":40.0573419755177,\"title\":\"Gravity\",\"vote_average\":7.9,\"vote_count\":751},{\"adult\":false,\"backdrop_path\":\"/3FweBee0xZoY77uO1bhUOlQorNH.jpg\",\"id\":76338,\"original_title\":\"Thor: The Dark World\",\"release_date\":\"2013-11-08\",\"poster_path\":\"/aROh4ZwLfv9tmtOAsrnkYTbpujA.jpg\",\"popularity\":38.5511611536454,\"title\":\"Thor: The Dark World\",\"vote_average\":7.1,\"vote_count\":503},{\"adult\":false,\"backdrop_path\":\"/dNPmXYRS3nN4vD7MLtz5lP79DCB.jpg\",\"id\":11824,\"original_title\":\"Teen Wolf\",\"release_date\":\"1985-08-23\",\"poster_path\":\"/3TKJbKNpHvRP8YVnwbgfok41AAC.jpg\",\"popularity\":37.546317184227,\"title\":\"Teen Wolf\",\"vote_average\":7.1,\"vote_count\":31},{\"adult\":false,\"backdrop_path\":\"/kJzvjhJP6Xf7QQofVl3y0NvpwmI.jpg\",\"id\":256731,\"original_title\":\"Bad Country\",\"release_date\":\"2014-03-10\",\"poster_path\":\"/6bjfGrtUYmuZzFCia3TcvY0Kz1e.jpg\",\"popularity\":37.123709776744,\"title\":\"Bad Country\",\"vote_average\":5.5,\"vote_count\":3},{\"adult\":false,\"backdrop_path\":\"/6Ace8kIosYGnAiJUHgbLO4MNI6k.jpg\",\"id\":77067,\"original_title\":\"DeadHeads\",\"release_date\":\"2011-04-29\",\"poster_path\":\"/A7kD47MEXywqKPeKHrxBfkvPTqy.jpg\",\"popularity\":36.41,\"title\":\"DeadHeads\",\"vote_average\":5.8,\"vote_count\":6}],\"total_pages\":7848,\"total_results\":156953}";
uuid = "bb4cca64-b0c4-0308-b92f-49980466092c";
}
The code that i tried till now
[MYCloud callFunctionInBackground:#"popularMovie"
withParameters:#{#"movie": #" "}
block:^(id response, NSError *error) {
if (!error) {
// ratings is 4.5
NSArray *movieArray;
movieArray = [response allValues];
NSDictionary *firstObject = [movieArray objectAtIndex:0];
NSDictionary *entities = [firstObject objectForKey:#"results"];
NSLog(#"json :%#",[response description]);
it crashes at NSDictionary *entities = [firstObject objectForKey:#"results"];
======================================================================================
this is the crash log on trying
NSDictionary *blah = [NSJSONSerialization JSONObjectWithData:response options:0 error:nil];
2014-03-29 16:21:48.572 Moviez[6804:60b] -[__NSDictionaryM bytes]: unrecognized selector sent to instance 0x9daf000
2014-03-29 16:21:48.575 Moviez[6804:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM bytes]: unrecognized selector sent to instance 0x9daf000'
* First throw call stack:
(
0 CoreFoundation 0x026271e4 exceptionPreprocess + 180
1 libobjc.A.dylib 0x023a68e5 objc_exception_throw + 44
2 CoreFoundation 0x026c4243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0261750b __forwarding + 1019
4 CoreFoundation 0x026170ee _CF_forwarding_prep_0 + 14
5 Foundation 0x020ec4bc -[_NSJSONReader findEncodingFromData:withBOMSkipLength:] + 36
6 Foundation 0x020ec66b -[_NSJSONReader parseData:options:] + 63
7 Foundation 0x020ecc30 +[NSJSONSerialization JSONObjectWithData:options:error:] + 161
8 Moviez 0x00002884 32-[HILViewController viewDidLoad]_block_invoke + 212
9 Moviez 0x00053f47 __40-[PFTask thenCallBackOnMainThreadAsync:]_block_invoke_2 + 241
10 libdispatch.dylib 0x02c7a7b8 _dispatch_call_block_and_release + 15
11 libdispatch.dylib 0x02c8f4d0 _dispatch_client_callout + 14
12 libdispatch.dylib 0x02c7d726 _dispatch_main_queue_callback_4CF + 340
13 CoreFoundation 0x0268c43e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 14
14 CoreFoundation 0x025cd5cb __CFRunLoopRun + 1963
15 CoreFoundation 0x025cc9d3 CFRunLoopRunSpecific + 467
16 CoreFoundation 0x025cc7eb CFRunLoopRunInMode + 123
17 GraphicsServices 0x0420b5ee GSEventRunModal + 192
18 GraphicsServices 0x0420b42b GSEventRun + 104
19 UIKit 0x01066f9b UIApplicationMain + 1225
20 Moviez 0x00002ded main + 141
21 libdyld.dylib 0x02ec4701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
UPDATED to match the full data you are getting
As you say response is already an NSDictionary so your code should be something like this...
// Results is an Array of movie entries
NSDictionary *movieData = [response objectForKey:#"data"];
NSArray * movieArray = [movieData objectForKey:#"results"];
NSDictionary *firstObject = [movieArray objectAtIndex:0];
Or in modern objective c you could do
NSDictionary *movieData = response[#"data"];
NSArray * movieArray = movieData[#"results"];
NSDictionary *firstObject = movieArray[0];
Or if you are really confident its always going to contain something you could do
NSDictionary *firstObject = response[#"data"][#"results"][0];
(I think)
Well the top level object is an NSDictionary.
So...
NSDictionary *blah = [NSJSONSerialization JSONObjectWithData:theData options:0 error:nil];
That will turn the data into an object that you can use.

Resources