-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathWebServiceParser.as
More file actions
51 lines (48 loc) · 1.63 KB
/
WebServiceParser.as
File metadata and controls
51 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package webService.types
{
/**this will generate dynamic classes from receved json*/
public class WebServiceParser
{
public static function pars(jsonString:String,classType:Class):Array
{
jsonString = jsonCorrector(jsonString);
var parsdObject:Object = {};
try
{
parsdObject = JSON.parse(jsonString);
}
catch(e)
{
trace("I cannot pars this JSON : "+jsonString);
return [];
}
var backdItems:Array = [] ;
//{ "VUserGroupMember":[{ "PartyId":"3", "UserTypeBaseId":"11", "UserName":"s1", "Password":"System.Byte[]", "IsActive":"True", "GroupId":"", "GroupTitle":"", "RoleBaseId":"", "RoleBaseTitle":"", "HasImage":"0"}]}
for each(var i in parsdObject)
{
var founded:Array = i ;
//[{ "PartyId":"3", "UserTypeBaseId":"11", "UserName":"s1", "Password":"System.Byte[]", "IsActive":"True", "GroupId":"", "GroupTitle":"", "RoleBaseId":"", "RoleBaseTitle":"", "HasImage":"0"}]
for(var j = 0 ; j<founded.length ; j++)
{
/*{ "PartyId":"3"
, "UserTypeBaseId":"11", "UserName":"s1", "Password":"System.Byte[]", "IsActive":"True", "GroupId":"", "GroupTitle":"", "RoleBaseId":"", "RoleBaseTitle":"", "HasImage":"0"}*/
var currentObject:Object = new classType();
for(var k in founded[j])
{
if(currentObject.hasOwnProperty(k))
{
currentObject[k] = founded[j][k] ;
}
}
backdItems.push(currentObject);
}
}
return backdItems ;
}
/**Correcting the json string*/
private static function jsonCorrector(oldJson:String)
{
return oldJson.split('\n').join(' \\n').split('\r').join(' \\r').split('"').join('\"').split('\t').join('\\t') ;
}
}
}