它返回一个空字符串,我似乎无法弄清楚为什么,如果你访问页面它输出正常。 (http://lgdev.site.nfoservers.com/getItems.php)。我正在尝试获取所有数据,将其与某些字符分开,然后使用游戏中的代码操作它并将其分类到正确的位置。但就像我说它返回一个空字符串而不是我在上面给出的网页上显示的数据。
游戏代码:
public void loadItems()
{
WWWForm form = new WWWForm();
WWW w = new WWW("http://lgdev.site.nfoservers.com/getItems.php", form);
StartCoroutine(loadItemsFunc(w));
}
IEnumerator loadItemsFunc(WWW w)
{
yield return w;
Debug.Log(w.text);
string[] tmpdata1 = w.text.Split(char.Parse("="));
foreach(string data in tmpdata1)
{
string[] tmpinfo = data.Split(char.Parse("~"));
GameObject tmpObj = Instantiate(weapon);
tmpObj.GetComponent<weapon>().name = tmpinfo[0];
tmpObj.GetComponent<weapon>().vitalisim = int.Parse(tmpinfo[1]);
tmpObj.GetComponent<weapon>().defence = int.Parse(tmpinfo[2]);
tmpObj.GetComponent<weapon>().strength = int.Parse(tmpinfo[3]);
string[] offsetInfo1 = tmpinfo[5].Split(char.Parse(";"));
foreach (string off in offsetInfo1)
{
string[] offset = off.Split(char.Parse(","));
tmpObj.GetComponent<weapon>().offsetsPos.Add(new Vector3(float.Parse(offset[0]), float.Parse(offset[1]), float.Parse(offset[2])));
tmpObj.GetComponent<weapon>().offetsRot.Add(new Vector3(float.Parse(offset[3]), float.Parse(offset[4]), float.Parse(offset[5])));
tmpObj.GetComponent<weapon>().offetsSize.Add(new Vector3(float.Parse(offset[6]), float.Parse(offset[7]), float.Parse(offset[8])));
}
string[] typeInfo = tmpinfo[4].Split(char.Parse(","));
if (tmpinfo[1] == "SwordnShield")
{
tmpObj.GetComponent<weapon>().anim = swordAndShieldAnimSet;
}
else if (tmpinfo[1] == "TwoHanded")
{
tmpObj.GetComponent<weapon>().anim = twoHandedAnimSet;
}
foreach (string prefab in tmpinfo[6].Split(char.Parse(",")))
{
tmpObj.GetComponent<weapon>().prefabs.Add(prefab);
}
}
}
PHP代码:
<?PHP
$con = mysql_connect("localhost","user","passs") or ("Cannot connect!" . mysql_error());
if (!$con)
die('Could not connect: ' . mysql_error());
mysql_select_db("lgdev_projectzed" , $con) or die ("could not load the database" . mysql_error());
$query = "SELECT * FROM `equipment`";
$check = mysql_query($query) or die(mysql_error()." ".$query);
if($check){
}
$numrows = mysql_num_rows($check);
$text = "";
while ($row = mysql_fetch_array($check, MYSQL_ASSOC)) {
$text = $text."".$row["name"]."~".$row["vitalism"]."~".$row["defence"]."~".$row["strength"]."~".$row["type"]."~".$row["offsets"]."~". $row["prefabs"] ."=";
}
die($text);
?>
答案 0 :(得分:1)
首先,检查是否有任何错误:
-(void)getAllContacts
{
//keys with fetching properties
NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey];
NSString *containerId = store.defaultContainerIdentifier;
//to fetch all contacts
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
//to fetch contacts with matching name
// NSPredicate *predicate = [CNContact predicateForContactsMatchingName:@"vishal"];
NSError *error;
NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
if (error) {
NSLog(@"error fetching contacts %@", error);
} else {
for (CNContact *contact in cnContacts) {
// copy data to my custom Contacts class.
Contact *newContact = [[Contact alloc] init];
newContact.firstName = contact.givenName;
newContact.lastName = contact.familyName;
UIImage *image = [UIImage imageWithData:contact.imageData];
newContact.image = image;
for (CNLabeledValue *label in contact.phoneNumbers) {
NSString *phone = [label.value stringValue];
if ([phone length] > 0) {
[newContact.phones addObject:phone];
}
}
[contacts addObject:newContact];
}
}
}
由于您提交的表单为空,因此存在一些错误。 因此,请检查如何设置表单: https://docs.unity3d.com/ScriptReference/WWWForm.html
如果您不需要在表单中发布任何内容,可以使用纯WWW https://docs.unity3d.com/ScriptReference/WWW.html