Write file from DListView ?

How would i go about writing all the data in a DListView box to a txt file? I know how to output the data & print out a list i just need to be able to write that to a file then load it back in the list when needed.

The easiest thing to do if you know how to read the data from the listview would probably be to encode the data into a string and write it into the file, then when it comes time to read the data, decode it back to its original state and populate the listview.

For example, you could loop through each line in the listview, add each line to a table, call something like util.TableToJSON and store the result into a file using file.Write. Later, you could read the data using file.Read and process it through util.JSONToTable, then loop thru the new table and add the lines back into the listview.

I know that von or some other kind of object notation could probably serve as a faster/more efficient/less shitty alternative to the built-in JSONToTable stuff, fyi

I think i got a little ahead of myself on this one i have only just begun to understand how loops & network strings work. if someone could show a example of this i would greatly appreciate it. heres what i got.


function GM.inv( ply, cmd, args )


local invbox = vgui.Create("DFrame")
local dropbtn = vgui.Create("DButton",invbox)
local dropbtn2 = vgui.Create("DButton",invbox)
local weplist = vgui.Create( "DListView", invbox )
local strlist = vgui.Create( "DListView", invbox )
local wlist = weplist:GetLines {}

--- call loadweps function from here---

	invbox:SetSize(500,300)
	invbox:MakePopup()
	invbox:SetVisible(true)
	invbox:SetTitle("Inventory")
	invbox:Center()


	dropbtn:SetPos(3,275)
	dropbtn:SetText("Add Current Tool/Weapon")
	dropbtn:SetWidth(150)
	dropbtn.DoClick = function()
	if ( table.HasValue( GMS.NonDropWeapons, ply:GetActiveWeapon():GetClass() ) ) then
		
		chat.AddText( "You can not add this tool/weapon" )

	else
	weplist:AddLine(ply:GetActiveWeapon():GetClass())


	ply:ConCommand("gms_dropweapon2")

end
end

	
	

	dropbtn2:SetPos(346,275)
	dropbtn2:SetText("Drop/Use")
	dropbtn2:SetWidth(150)



	weplist:SetPos(20,50)
	weplist:SetSize(200,200)
	weplist:SetParent(invbox)
	weplist:SetMultiSelect( false )
	weplist:AddColumn( "Weapons And Tools" )
	--weplist:AddColumn( "Amount" )



	strlist:SetPos(280,50)
	strlist:SetSize(200,200)
	strlist:SetParent(invbox)
	strlist:SetMultiSelect( false )
	strlist:AddColumn( "Structures" )
	--strlist:AddColumn( "Amount" )

function invbox:OnClose ()
	print ("Loadout Saved")

---call the saveweps function----


for k, wlist in pairs( weplist:GetLines() ) do --this prints the table that i want to be saved to a file i just dont know how--

	print( k, wlist:GetValue( 1 ) )



end
end


end
concommand.Add( "gms_inv", GM.inv )


I have no clue what to do next like how to make a NWString thats a table to use in init so the data will save to the server all i know is i need a save & load function in init just have no clue how to do it.