item_id = $itemID; $item->num = $num; $itemConfig = GameConfigServices::getParamByPath('item_list.' . $itemID); $item->name = $itemConfig['name']; array_push($this->item_list, $item); return $item; } public function toReadString() { if ($this->gold > 0) { return '金币:' . $this->gold; } else { $str = ''; foreach ($this->item_list as $item) { $str .= sprintf('%sX%s;', $item->name, $item->num); } return $str; } } /** * @param $json * @return DealData */ public static function loadJson($json) { $jsonObj = json_decode($json ); $data = new DealData(); $data->gold = $jsonObj->gold; $data->item_list = $jsonObj->item_list; return $data; } }