public static DetailPOJO Instance() { if (singleton == null) { singleton = new DetailPOJO(); } return(singleton); }
/// <summary> /// DetailPOJO 对象序列化 为 json字符串 /// ser.RecursionLimit = 6 设置递归深度为 6 /// </summary> /// <returns></returns> public static string ToJson() { JavaScriptSerializer ser = new JavaScriptSerializer(); ser.RecursionLimit = 6; DetailPOJO pojo = DetailPOJO.Instance(); string json = ser.Serialize(pojo); return(json); }
public ServiceModule() { //测试用 Get["/test"] = (x => "ok"); // 获取游戏数据 Get["/data"] = _ => { DetailPOJO pojo = DetailPOJO.Instance(); // 存储当前数据的对象 string json = Convert.ToJson(); // 转换为Json字符串 return(json); }; }
/// <summary> /// Detail 对象转换为 DetailPOJO 对象 /// </summary> /// <returns></returns> public static DetailPOJO ConvertDetail() { DetailPOJO pojo = DetailPOJO.Instance(); pojo.car = ConvertVehicle(Detail.car); pojo.charactor = ConvertPed(Detail.player.Character); pojo.time_since_player_drove_against_traffic = Detail.time_since_player_drove_against_traffic; pojo.time_since_player_drove_on_pavement = Detail.time_since_player_drove_on_pavement; pojo.time_since_player_hit_ped = Detail.time_since_player_hit_ped; pojo.time_since_player_hit_vehicle = Detail.time_since_player_hit_vehicle; pojo.startPosition = ConvertVector3(Detail.StartPosition); pojo.endPosition = ConvertVector3(Detail.EndPosition); pojo.near_by_vehicles = new List <VehiclePOJO>(); for (int i = 0; i < Detail.near_by_vehicles.Count; i++) { pojo.near_by_vehicles.Add(ConvertVehicle(Detail.near_by_vehicles[i])); } pojo.near_by_peds = new List <PedPOJO>(); for (int i = 0; i < Detail.near_by_peds.Count; i++) { pojo.near_by_peds.Add(ConvertPed(Detail.near_by_peds[i])); } pojo.near_by_props = new List <EntityPOJO>(); for (int i = 0; i < Detail.near_by_props.Count; i++) { pojo.near_by_props.Add(ConvertEntity(Detail.near_by_props[i])); } pojo.near_by_touching_peds = new List <PedPOJO>(); for (int i = 0; i < Detail.near_by_touching_peds.Count; i++) { pojo.near_by_touching_peds.Add(ConvertPed(Detail.near_by_touching_peds[i])); } pojo.near_by_touching_props = new List <EntityPOJO>(); for (int i = 0; i < Detail.near_by_touching_props.Count; i++) { pojo.near_by_touching_props.Add(ConvertEntity(Detail.near_by_touching_props[i])); } pojo.near_by_touching_vehicles = new List <VehiclePOJO>(); for (int i = 0; i < Detail.near_by_touching_vehicles.Count; i++) { pojo.near_by_touching_vehicles.Add(ConvertVehicle(Detail.near_by_touching_vehicles[i])); } pojo.next_position_on_street = ConvertVector3(Detail.next_position_on_street); pojo.forward_vector3 = ConvertVector3(Detail.car.ForwardVector); pojo.radius = Detail.radius; pojo.is_ped_injured = Detail.is_ped_injured; pojo.is_ped_in_any_vehicle = Detail.is_ped_in_any_vehicle; pojo.onRoad = Detail.onRoad; pojo.is_player_in_water = Detail.is_player_in_water; return(pojo); }